From 8a2de0b7112706fd16fc0cf7478d0d4c9355a14a Mon Sep 17 00:00:00 2001 From: Michael Blizek Date: Sat, 29 May 2021 07:10:00 +0200 Subject: [PATCH] routed: interface configuration --- src/demo/libcor.h | 2 -- src/routed/conf.c | 45 +++++++++++++++++++++++--- src/routed/libcor.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++----- src/routed/libcor.h | 11 ++++--- src/routed/main.c | 3 +- src/routed/routed.h | 4 +++ 6 files changed, 138 insertions(+), 20 deletions(-) diff --git a/src/demo/libcor.h b/src/demo/libcor.h index ac59dba..8b86952 100644 --- a/src/demo/libcor.h +++ b/src/demo/libcor.h @@ -31,13 +31,11 @@ #define CRD_UTK_VERSION 1 /* * CRD_UTK_VERSION[4] length[4] version[4] - * */ #define CRD_UTK_UP 2 /* * CRD_UTK_UP[4] length[4] flags[8] addrlen[4] addr[addrlen] - * */ diff --git a/src/routed/conf.c b/src/routed/conf.c index bb2b431..87d4e7d 100644 --- a/src/routed/conf.c +++ b/src/routed/conf.c @@ -26,11 +26,36 @@ char *localaddr; __u16 localaddrlen; +char **interfaces = 0; +__u32 num_interfaces = 0; +int all_interfaces = 0; + __u32 sleep_before_discover = 5; __u8 export_servicelist_enabled = 0; __u32 verbosity = 1; + +static int parse_interface(char *arg) +{ + if (strcmp(arg, "*") == 0) { + all_interfaces = 1; + return 0; + } + + if (num_interfaces == 0) { + interfaces = malloc(sizeof(char *)); + } else { + interfaces = realloc(interfaces, + sizeof(char *) * (num_interfaces+1)); + } + + interfaces[num_interfaces] = arg; + num_interfaces++; + + return 0; +} + static int _parse_addr(char *arg, size_t arg_len, char **addr, __u16 *addrlen, int noaddr_allowed) { @@ -420,6 +445,15 @@ int parse_args(int argc, char *argv[], struct list_head *r_fwds, addrfound = 1; argsconsumed += 2; + } else if (strcmp(argv[argsconsumed + 1], "--intf") == 0) { + if (argc <= argsconsumed + 2) + goto usage; + + rc = parse_interface(argv[argsconsumed + 2]); + if (rc != 0) + goto usage; + + argsconsumed += 2; } else if (strcmp(argv[argsconsumed + 1], "--export-servicelist") == 0) { export_servicelist_enabled = 1; @@ -479,12 +513,13 @@ int parse_args(int argc, char *argv[], struct list_head *r_fwds, return 0; usage: - fprintf(stderr, "usage: test_routed2" + fprintf(stderr, "usage: test_routed2\n" " [--export-servicelist]" - " [--fwd-to-rservice bindaddr:bindport:remoteport]" - " [--fwd-to-rhost bindaddr:bindport:remotaaddr:remoteport]" - " [--fwd-to-lservice bindport:localaddr:localport]" - " [--fwd-to-lservice-pub bindport:localaddr:localport]" + " [--fwd-to-rservice bindaddr:bindport:remoteport]\n" + " [--fwd-to-rhost bindaddr:bindport:remotaaddr:remoteport]\n" + " [--fwd-to-lservice bindport:localaddr:localport]\n" + " [--fwd-to-lservice-pub bindport:localaddr:localport]\n" + " [--intf intf|*] (only localhost connectivity if omitted)" " --addr addr (even number of hex digits or noaddr)\n"); return 1; } diff --git a/src/routed/libcor.c b/src/routed/libcor.c index d01b82d..a389908 100644 --- a/src/routed/libcor.c +++ b/src/routed/libcor.c @@ -1064,15 +1064,75 @@ int send_rdsock_version(int fd, __u32 version) return rc; } +static __u32 _send_rdsock_up_interfacelen(char **interfaces, + __u32 num_interfaces) +{ + __u32 len = 0; + __u32 i; + + for (i=0;i 0) - memcpy(&(data[12]), addr, addrlen); + memcpy(buf + 12, addr, addrlen); - return send_rdsock_cmd(fd, nr, CRD_UTK_UP, &(data[0]), 12 + addrlen); + if (!all_interfaces) { + interface_len2 = _send_rdsock_up_interfaces(interfaces, + num_interfaces, + buf + 12 + addrlen, interface_len); + ASSERT(interface_len == interface_len2); + } + + rc = send_rdsock_cmd(fd, nr, CRD_UTK_UP, buf, + 12 + addrlen + interface_len); + + free(buf); + buf = 0; + return rc; } -int send_rdsock_up(int fd, char *addr, __u32 addrlen) +int send_rdsock_up(int fd, char *addr, __u32 addrlen, + char **interfaces, __u32 num_interfaces, int all_interfaces) { int rc = RC_WOULDBLOCK; struct libcor_nonblock_resumeinfo nr; bzero(&nr, sizeof(struct libcor_nonblock_resumeinfo)); - rc = send_rdsock_up_nonblock(fd, &nr, addr, addrlen); + rc = send_rdsock_up_nonblock(fd, &nr, addr, addrlen, + interfaces, num_interfaces, all_interfaces); if (unlikely(rc == RC_WOULDBLOCK)) { ASSERT_ERR(); return bzero_nr_iffinished(&nr, RC_CONNBROKEN); diff --git a/src/routed/libcor.h b/src/routed/libcor.h index 1b75697..be851ad 100644 --- a/src/routed/libcor.h +++ b/src/routed/libcor.h @@ -31,13 +31,14 @@ #define CRD_UTK_VERSION 1 /* * CRD_UTK_VERSION[4] length[4] version[4] - * */ #define CRD_UTK_UP 2 +#define CRD_UTK_UP_FLAGS_INTERFACES 1 /* * CRD_UTK_UP[4] length[4] flags[8] addrlen[4] addr[addrlen] - * + * if CRD_UTK_UP_FLAGS_INTERFACES: + * num_interfaces[4] (length[4] interface[length])[num_interfaces] */ @@ -224,9 +225,11 @@ extern int send_rdsock_version(int fd, __u32 version); extern int send_rdsock_up_nonblock(int fd, struct libcor_nonblock_resumeinfo *nr, - char *addr, __u32 addrlen); + char *addr, __u32 addrlen, + char **interfaces, __u32 num_interfaces, int all_interfaces); -extern int send_rdsock_up(int fd, char *addr, __u32 addrlen); +extern int send_rdsock_up(int fd, char *addr, __u32 addrlen, + char **interfaces, __u32 num_interfaces, int all_interfaces); extern int send_rdsock_connecterror_nonblock(int fd, struct libcor_nonblock_resumeinfo *nr, diff --git a/src/routed/main.c b/src/routed/main.c index 0282722..853fc88 100644 --- a/src/routed/main.c +++ b/src/routed/main.c @@ -447,7 +447,8 @@ int main(int argc, char *argv[]) if (rc != 0) goto out; - rc = send_rdsock_up(rdsock_fd, localaddr, localaddrlen); + rc = send_rdsock_up(rdsock_fd, localaddr, localaddrlen, + interfaces, num_interfaces, all_interfaces); ASSERT(rc == RC_OK); set_nonblock(rdsock_fd, 1); diff --git a/src/routed/routed.h b/src/routed/routed.h index ab69142..8e38618 100644 --- a/src/routed/routed.h +++ b/src/routed/routed.h @@ -260,6 +260,10 @@ extern void neigh_printaddr(__u16 addrlen, char *addr); extern char *localaddr; extern __u16 localaddrlen; +extern char **interfaces; +extern __u32 num_interfaces; +extern int all_interfaces; + extern __u32 sleep_before_discover; extern __u8 export_servicelist_enabled; -- 2.11.4.GIT