summaryrefslogtreecommitdiff
path: root/src/xdp
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-12-19 21:13:34 +0000
committerChristian Poessinger <christian@poessinger.com>2020-12-19 21:13:34 +0000
commitae567b86495bf0bbadf19d396df60186979558a4 (patch)
tree5b82baa4432680d2d366f8200e00cd18b22f7ced /src/xdp
parentb5c80d310527223b93e4133ac2f4c8c063c70a98 (diff)
downloadvyos-1x-ae567b86495bf0bbadf19d396df60186979558a4.tar.gz
vyos-1x-ae567b86495bf0bbadf19d396df60186979558a4.zip
xdp: T2666: use proper xdp_prog_user.c code
Diffstat (limited to 'src/xdp')
-rw-r--r--src/xdp/xdp_prog_user.c47
1 files changed, 39 insertions, 8 deletions
diff --git a/src/xdp/xdp_prog_user.c b/src/xdp/xdp_prog_user.c
index d91610791..c47d2977d 100644
--- a/src/xdp/xdp_prog_user.c
+++ b/src/xdp/xdp_prog_user.c
@@ -50,10 +50,34 @@ static const struct option_wrapper long_options[] = {
{{0, 0, NULL, 0 }, NULL, false}
};
+static int parse_u8(char *str, unsigned char *x)
+{
+ unsigned long z;
+
+ z = strtoul(str, 0, 16);
+ if (z > 0xff)
+ return -1;
+
+ if (x)
+ *x = z;
+
+ return 0;
+}
+
static int parse_mac(char *str, unsigned char mac[ETH_ALEN])
{
- /* Assignment 3: parse a MAC address in this function and place the
- * result in the mac array */
+ if (parse_u8(str, &mac[0]) < 0)
+ return -1;
+ if (parse_u8(str + 3, &mac[1]) < 0)
+ return -1;
+ if (parse_u8(str + 6, &mac[2]) < 0)
+ return -1;
+ if (parse_u8(str + 9, &mac[3]) < 0)
+ return -1;
+ if (parse_u8(str + 12, &mac[4]) < 0)
+ return -1;
+ if (parse_u8(str + 15, &mac[5]) < 0)
+ return -1;
return 0;
}
@@ -123,9 +147,11 @@ int main(int argc, char **argv)
return EXIT_FAIL_OPTION;
}
-
- /* Assignment 3: open the tx_port map corresponding to the cfg.ifname interface */
- map_fd = -1;
+ /* Open the tx_port map corresponding to the cfg.ifname interface */
+ map_fd = open_bpf_map_file(pin_dir, "tx_port", NULL);
+ if (map_fd < 0) {
+ return EXIT_FAIL_BPF;
+ }
printf("map dir: %s\n", pin_dir);
@@ -135,8 +161,11 @@ int main(int argc, char **argv)
bpf_map_update_elem(map_fd, &i, &cfg.redirect_ifindex, 0);
printf("redirect from ifnum=%d to ifnum=%d\n", cfg.ifindex, cfg.redirect_ifindex);
- /* Assignment 3: open the redirect_params map corresponding to the cfg.ifname interface */
- map_fd = -1;
+ /* Open the redirect_params map */
+ map_fd = open_bpf_map_file(pin_dir, "redirect_params", NULL);
+ if (map_fd < 0) {
+ return EXIT_FAIL_BPF;
+ }
/* Setup the mapping containing MAC addresses */
if (write_iface_params(map_fd, src, dest) < 0) {
@@ -144,7 +173,9 @@ int main(int argc, char **argv)
return 1;
}
} else {
- /* Assignment 4: setup 1-1 mapping for the dynamic router */
+ /* setup 1-1 mapping for the dynamic router */
+ for (i = 1; i < 256; ++i)
+ bpf_map_update_elem(map_fd, &i, &i, 0);
}
return EXIT_OK;