From a3f86cd20c2f5a0b718d76382c8ef043e702d890 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 17 Aug 2010 19:46:41 +0200 Subject: [PATCH] Implement an option for setting static routes with gateway --- main.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index ef669fa..407c8c2 100644 --- a/main.c +++ b/main.c @@ -635,6 +635,8 @@ static int usage(const char *progname) " -I Same as -i, except with ARP cache and host route management\n" " You need to specify at least two interfaces\n" " -G Set a gateway IP for clients\n" + " -R :/\n" + " Add a static route for / via \n" " -t Host entry expiry timeout\n" " -T Set routing table number for automatically added routes\n" " -B Enable broadcast forwarding\n" @@ -647,9 +649,11 @@ static int usage(const char *progname) int main(int argc, char **argv) { struct relayd_interface *rif = NULL; - struct in_addr addr; + struct in_addr addr, addr2; bool managed; int ifnum = 0; + char *s, *s2; + int mask; int ch; debug = 0; @@ -663,7 +667,7 @@ int main(int argc, char **argv) forward_bcast = 0; uloop_init(); - while ((ch = getopt(argc, argv, "I:i:t:BDdT:G:")) != -1) { + while ((ch = getopt(argc, argv, "I:i:t:BDdT:G:R:")) != -1) { switch(ch) { case 'I': managed = true; @@ -702,6 +706,33 @@ int main(int argc, char **argv) } relayd_add_pending_route((uint8_t *) &addr.s_addr, (const uint8_t *) "\x00\x00\x00\x00", 0, 0); break; + case 'R': + s = strchr(optarg, ':'); + if (!s) + return usage(argv[0]); + + *(s++) = 0; + if (!inet_aton(optarg, &addr)) { + fprintf(stderr, "Address '%s' not found\n", optarg); + return 1; + } + + s2 = strchr(s, '/'); + if (!s2) + return usage(argv[0]); + + *(s2++) = 0; + if (!inet_aton(s, &addr2)) { + fprintf(stderr, "Address '%s' not found\n", s); + return 1; + } + + mask = atoi(s2); + if (mask < 0 || mask > 32) + return usage(argv[0]); + + relayd_add_pending_route((uint8_t *) &addr.s_addr, (uint8_t *) &addr2.s_addr, mask, 0); + break; case '?': default: return usage(argv[0]); -- 2.25.1