X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=main.c;h=b3c13f7f7a49f3693df2efa1adfcae8dbaba56cf;hb=HEAD;hp=a78076c7f1b37e972ac83f0ce10197de44d99ad3;hpb=d49528ef9ccc74a90b0828fcd94408374a8af4b1;p=project%2Frelayd.git diff --git a/main.c b/main.c index a78076c..b3c13f7 100644 --- a/main.c +++ b/main.c @@ -40,6 +40,7 @@ static int host_ping_tries; static int inet_sock; static int forward_bcast; static int forward_dhcp; +static int parse_dhcp; uint8_t local_addr[4]; int local_route_table; @@ -164,7 +165,7 @@ static void send_arp_request(struct relayd_interface *rif, const uint8_t *ipaddr fill_arp_packet(&pkt, rif, rif->src_ip, ipaddr); pkt.arp.arp_op = htons(ARPOP_REQUEST); - memcpy(pkt.arp.arp_spa, rif->src_ip, ETH_ALEN); + memcpy(pkt.arp.arp_spa, rif->src_ip, sizeof(pkt.arp.arp_spa)); memset(pkt.arp.arp_tha, 0, ETH_ALEN); memset(pkt.eth.ether_dhost, 0xff, ETH_ALEN); @@ -252,6 +253,7 @@ static void send_arp_reply(struct relayd_interface *rif, const uint8_t spa[4], static void host_entry_timeout(struct uloop_timeout *timeout) { struct relayd_host *host = container_of(timeout, struct relayd_host, timeout); + struct relayd_interface *rif; /* * When a host is behind a managed interface, we must not expire its host @@ -261,7 +263,9 @@ static void host_entry_timeout(struct uloop_timeout *timeout) * giving up on it. */ if (host->rif->managed && host->cleanup_pending < host_ping_tries) { - send_arp_request(host->rif, host->ipaddr); + list_for_each_entry(rif, &interfaces, list) { + send_arp_request(rif, host->ipaddr); + } host->cleanup_pending++; uloop_timeout_set(&host->timeout, 1000); return; @@ -504,7 +508,7 @@ static void recv_bcast_packet(struct uloop_fd *fd, unsigned int events) if (!forward_bcast && !forward_dhcp) continue; - if (relayd_handle_dhcp_packet(rif, pktbuf, pktlen, forward_dhcp)) + if (relayd_handle_dhcp_packet(rif, pktbuf, pktlen, forward_dhcp, parse_dhcp)) continue; if (forward_bcast) @@ -649,6 +653,11 @@ static struct relayd_interface *alloc_interface(const char *ifname, bool managed if (strlen(ifname) >= IFNAMSIZ) return NULL; + list_for_each_entry(rif, &interfaces, list) { + if (!strncmp(rif->ifname, ifname, IFNAMSIZ)) + return rif; + } + rif = calloc(1, sizeof(*rif)); if (!rif) return NULL; @@ -667,9 +676,7 @@ static void die(int signo) * When we hit SIGTERM, clean up interfaces directly, so that we * won't leave our routing in an invalid state. */ - cleanup_hosts(); - free_interfaces(); - exit(1); + uloop_end(); } static int usage(const char *progname) @@ -689,6 +696,7 @@ static int usage(const char *progname) " -T Set routing table number for automatically added routes\n" " -B Enable broadcast forwarding\n" " -D Enable DHCP forwarding\n" + " -P Disable DHCP options parsing\n" " -L Enable local access using as source address\n" "\n", progname); @@ -700,7 +708,7 @@ int main(int argc, char **argv) struct relayd_interface *rif = NULL; struct in_addr addr, addr2; bool local_addr_valid = false; - bool managed; + bool managed = false; int ifnum = 0; char *s, *s2; int mask; @@ -717,9 +725,10 @@ int main(int argc, char **argv) host_ping_tries = 5; forward_bcast = 0; local_route_table = 0; + parse_dhcp = 1; uloop_init(); - while ((ch = getopt(argc, argv, "I:i:t:p:BDdT:G:R:L:")) != -1) { + while ((ch = getopt(argc, argv, "I:i:t:p:BDPdT:G:R:L:")) != -1) { switch(ch) { case 'I': managed = true; @@ -751,6 +760,9 @@ int main(int argc, char **argv) case 'D': forward_dhcp = 1; break; + case 'P': + parse_dhcp = 0; + break; case 'T': route_table = atoi(optarg); if (route_table <= 0)