From: Hans Dedecker Date: Wed, 6 Sep 2017 12:51:09 +0000 (+0200) Subject: treewide: replace RELAYD prefix naming in macros X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=f0e354befd6f787c1ed8ebc1ea514e9195f54433;p=project%2Fodhcpd.git treewide: replace RELAYD prefix naming in macros Remove the unfortunate RELAYD naming in the different macros Signed-off-by: Hans Dedecker --- diff --git a/src/config.c b/src/config.c index 8bf2011..fd8f32e 100644 --- a/src/config.c +++ b/src/config.c @@ -249,13 +249,13 @@ static void close_interface(struct interface *iface) static int parse_mode(const char *mode) { if (!strcmp(mode, "disabled")) - return RELAYD_DISABLED; + return MODE_DISABLED; else if (!strcmp(mode, "server")) - return RELAYD_SERVER; + return MODE_SERVER; else if (!strcmp(mode, "relay")) - return RELAYD_RELAY; + return MODE_RELAY; else if (!strcmp(mode, "hybrid")) - return RELAYD_HYBRID; + return MODE_HYBRID; else return -1; } @@ -478,7 +478,7 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr iface->dhcpv4_start.s_addr = htonl(blobmsg_get_u32(c)); if (config.main_dhcpv4 && config.legacy) - iface->dhcpv4 = RELAYD_SERVER; + iface->dhcpv4 = MODE_SERVER; } if ((c = tb[IFACE_ATTR_LIMIT])) @@ -778,13 +778,13 @@ void odhcpd_reload(void) if (i->master) continue; - if (i->dhcpv6 == RELAYD_HYBRID || i->dhcpv6 == RELAYD_RELAY) + if (i->dhcpv6 == MODE_HYBRID || i->dhcpv6 == MODE_RELAY) any_dhcpv6_slave = true; - if (i->ra == RELAYD_HYBRID || i->ra == RELAYD_RELAY) + if (i->ra == MODE_HYBRID || i->ra == MODE_RELAY) any_ra_slave = true; - if (i->ndp == RELAYD_HYBRID || i->ndp == RELAYD_RELAY) + if (i->ndp == MODE_HYBRID || i->ndp == MODE_RELAY) any_ndp_slave = true; } @@ -793,31 +793,31 @@ void odhcpd_reload(void) if (!i->master) continue; - enum odhcpd_mode hybrid_mode = RELAYD_DISABLED; + enum odhcpd_mode hybrid_mode = MODE_DISABLED; #ifdef WITH_UBUS if (!ubus_has_prefix(i->name, i->ifname)) - hybrid_mode = RELAYD_RELAY; + hybrid_mode = MODE_RELAY; #endif - if (i->dhcpv6 == RELAYD_HYBRID) + if (i->dhcpv6 == MODE_HYBRID) i->dhcpv6 = hybrid_mode; - if (i->dhcpv6 == RELAYD_RELAY && !any_dhcpv6_slave) - i->dhcpv6 = RELAYD_DISABLED; + if (i->dhcpv6 == MODE_RELAY && !any_dhcpv6_slave) + i->dhcpv6 = MODE_DISABLED; - if (i->ra == RELAYD_HYBRID) + if (i->ra == MODE_HYBRID) i->ra = hybrid_mode; - if (i->ra == RELAYD_RELAY && !any_ra_slave) - i->ra = RELAYD_DISABLED; + if (i->ra == MODE_RELAY && !any_ra_slave) + i->ra = MODE_DISABLED; - if (i->ndp == RELAYD_HYBRID) + if (i->ndp == MODE_HYBRID) i->ndp = hybrid_mode; - if (i->ndp == RELAYD_RELAY && !any_ndp_slave) - i->ndp = RELAYD_DISABLED; + if (i->ndp == MODE_RELAY && !any_ndp_slave) + i->ndp = MODE_DISABLED; - if (i->dhcpv6 == RELAYD_RELAY || i->ra == RELAYD_RELAY || i->ndp == RELAYD_RELAY) + if (i->dhcpv6 == MODE_RELAY || i->ra == MODE_RELAY || i->ndp == MODE_RELAY) master = i; } @@ -825,22 +825,22 @@ void odhcpd_reload(void) list_for_each_entry_safe(i, n, &interfaces, head) { if (i->inuse) { /* Resolve hybrid mode */ - if (i->dhcpv6 == RELAYD_HYBRID) - i->dhcpv6 = (master && master->dhcpv6 == RELAYD_RELAY) ? - RELAYD_RELAY : RELAYD_SERVER; - - if (i->ra == RELAYD_HYBRID) - i->ra = (master && master->ra == RELAYD_RELAY) ? - RELAYD_RELAY : RELAYD_SERVER; - - if (i->ndp == RELAYD_HYBRID) - i->ndp = (master && master->ndp == RELAYD_RELAY) ? - RELAYD_RELAY : RELAYD_DISABLED; - - setup_router_interface(i, !i->ignore || i->ra != RELAYD_DISABLED); - setup_dhcpv6_interface(i, !i->ignore || i->dhcpv6 != RELAYD_DISABLED); - setup_ndp_interface(i, !i->ignore || i->ndp != RELAYD_DISABLED); - setup_dhcpv4_interface(i, !i->ignore || i->dhcpv4 != RELAYD_DISABLED); + if (i->dhcpv6 == MODE_HYBRID) + i->dhcpv6 = (master && master->dhcpv6 == MODE_RELAY) ? + MODE_RELAY : MODE_SERVER; + + if (i->ra == MODE_HYBRID) + i->ra = (master && master->ra == MODE_RELAY) ? + MODE_RELAY : MODE_SERVER; + + if (i->ndp == MODE_HYBRID) + i->ndp = (master && master->ndp == MODE_RELAY) ? + MODE_RELAY : MODE_DISABLED; + + setup_router_interface(i, !i->ignore || i->ra != MODE_DISABLED); + setup_dhcpv6_interface(i, !i->ignore || i->dhcpv6 != MODE_DISABLED); + setup_ndp_interface(i, !i->ignore || i->ndp != MODE_DISABLED); + setup_dhcpv4_interface(i, !i->ignore || i->dhcpv4 != MODE_DISABLED); } else close_interface(i); } diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index 04d92fe..bd4342b 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -64,7 +64,7 @@ int setup_dhcpv6_ia_interface(struct interface *iface, bool enable) } } - if (enable && iface->dhcpv6 == RELAYD_SERVER) { + if (enable && iface->dhcpv6 == MODE_SERVER) { if (!iface->ia_assignments.next) INIT_LIST_HEAD(&iface->ia_assignments); @@ -347,11 +347,11 @@ void dhcpv6_write_statefile(void) ctxt.buf_len = sizeof(leasebuf); list_for_each_entry(ctxt.iface, &interfaces, head) { - if (ctxt.iface->dhcpv6 != RELAYD_SERVER && - ctxt.iface->dhcpv4 != RELAYD_SERVER) + if (ctxt.iface->dhcpv6 != MODE_SERVER && + ctxt.iface->dhcpv4 != MODE_SERVER) continue; - if (ctxt.iface->dhcpv6 == RELAYD_SERVER && + if (ctxt.iface->dhcpv6 == MODE_SERVER && ctxt.iface->ia_assignments.next) { list_for_each_entry(ctxt.c, &ctxt.iface->ia_assignments, head) { if (!(ctxt.c->flags & OAF_BOUND) || ctxt.c->managed_size < 0) @@ -379,7 +379,7 @@ void dhcpv6_write_statefile(void) } } - if (ctxt.iface->dhcpv4 == RELAYD_SERVER && + if (ctxt.iface->dhcpv4 == MODE_SERVER && ctxt.iface->dhcpv4_assignments.next) { struct dhcpv4_assignment *c; list_for_each_entry(c, &ctxt.iface->dhcpv4_assignments, head) { @@ -657,7 +657,7 @@ static bool assign_na(struct interface *iface, struct dhcpv6_assignment *assign) void dhcpv6_ia_preupdate(struct interface *iface) { - if (iface->dhcpv6 != RELAYD_SERVER) + if (iface->dhcpv6 != MODE_SERVER) return; struct dhcpv6_assignment *c, *border = list_last_entry( @@ -701,7 +701,7 @@ static void stop_reconf(struct dhcpv6_assignment *a) void dhcpv6_ia_postupdate(struct interface *iface) { - if (iface->dhcpv6 != RELAYD_SERVER) + if (iface->dhcpv6 != MODE_SERVER) return; time_t now = odhcpd_time(); @@ -762,7 +762,7 @@ static void valid_until_cb(struct uloop_timeout *event) time_t now = odhcpd_time(); struct interface *iface; list_for_each_entry(iface, &interfaces, head) { - if (iface->dhcpv6 != RELAYD_SERVER || iface->ia_assignments.next == NULL) + if (iface->dhcpv6 != MODE_SERVER || iface->ia_assignments.next == NULL) continue; struct dhcpv6_assignment *a, *n; diff --git a/src/dhcpv6.c b/src/dhcpv6.c index 4ecb54a..902bdbf 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -87,7 +87,7 @@ int setup_dhcpv6_interface(struct interface *iface, bool enable) struct ipv6_mreq server = {ALL_DHCPV6_SERVERS, iface->ifindex}; setsockopt(sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &relay, sizeof(relay)); - if (iface->dhcpv6 == RELAYD_SERVER) + if (iface->dhcpv6 == MODE_SERVER) setsockopt(sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &server, sizeof(server)); iface->dhcpv6_event.uloop.fd = sock; @@ -381,9 +381,9 @@ static void handle_client_request(void *addr, void *data, size_t len, static void handle_dhcpv6(void *addr, void *data, size_t len, struct interface *iface, void *dest_addr) { - if (iface->dhcpv6 == RELAYD_SERVER) { + if (iface->dhcpv6 == MODE_SERVER) { handle_client_request(addr, data, len, iface, dest_addr); - } else if (iface->dhcpv6 == RELAYD_RELAY) { + } else if (iface->dhcpv6 == MODE_RELAY) { if (iface->master) relay_server_response(data, len); else @@ -507,7 +507,7 @@ static void relay_client_request(struct sockaddr_in6 *source, { struct interface *master = odhcpd_get_master_interface(); const struct dhcpv6_relay_header *h = data; - if (!master || master->dhcpv6 != RELAYD_RELAY || + if (!master || master->dhcpv6 != MODE_RELAY || h->msg_type == DHCPV6_MSG_RELAY_REPL || h->msg_type == DHCPV6_MSG_RECONFIGURE || h->msg_type == DHCPV6_MSG_REPLY || diff --git a/src/ndp.c b/src/ndp.c index 33dde87..e0e865f 100644 --- a/src/ndp.c +++ b/src/ndp.c @@ -187,13 +187,13 @@ int setup_ndp_interface(struct interface *iface, bool enable) close(iface->ndp_event.uloop.fd); iface->ndp_event.uloop.fd = -1; - if (!enable || iface->ndp != RELAYD_RELAY) + if (!enable || iface->ndp != MODE_RELAY) if (write(procfd, "0\n", 2) < 0) {} dump_neigh = true; } - if (enable && iface->ndp == RELAYD_RELAY) { + if (enable && iface->ndp == MODE_RELAY) { if (write(procfd, "1\n", 2) < 0) {} int sock = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_IPV6)); @@ -286,7 +286,7 @@ static void handle_solicit(void *addr, void *data, size_t len, // Don't process solicit messages on non relay interfaces // Don't forward any non-DAD solicitation for external ifaces // TODO: check if we should even forward DADs for them - if (iface->ndp != RELAYD_RELAY || (iface->external && !ns_is_dad)) + if (iface->ndp != MODE_RELAY || (iface->external && !ns_is_dad)) return; if (len < sizeof(*ip6) + sizeof(*req)) @@ -306,7 +306,7 @@ static void handle_solicit(void *addr, void *data, size_t len, struct interface *c; list_for_each_entry(c, &interfaces, head) - if (iface != c && c->ndp == RELAYD_RELAY && + if (iface != c && c->ndp == MODE_RELAY && (ns_is_dad || !c->external)) ping6(&req->nd_ns_target, c); } @@ -382,10 +382,10 @@ static void setup_addr_for_relaying(struct in6_addr *addr, struct interface *ifa inet_ntop(AF_INET6, addr, ipbuf, sizeof(ipbuf)); list_for_each_entry(c, &interfaces, head) { - if (iface == c || (c->ndp != RELAYD_RELAY && !add)) + if (iface == c || (c->ndp != MODE_RELAY && !add)) continue; - bool neigh_add = (c->ndp == RELAYD_RELAY ? add : false); + bool neigh_add = (c->ndp == MODE_RELAY ? add : false); if (odhcpd_setup_proxy_neigh(addr, c, neigh_add)) syslog(LOG_DEBUG, "Failed to %s proxy neighbour entry %s%%%s", @@ -463,7 +463,7 @@ static int cb_rtnl_valid(struct nl_msg *msg, _unused void *arg) check_addr6_updates(iface); - if (iface->ndp != RELAYD_RELAY) + if (iface->ndp != MODE_RELAY) break; /* handle the relay logic below */ @@ -498,7 +498,7 @@ static int cb_rtnl_valid(struct nl_msg *msg, _unused void *arg) return NL_SKIP; iface = odhcpd_get_interface_by_index(ndm->ndm_ifindex); - if (!iface || iface->ndp != RELAYD_RELAY) + if (!iface || iface->ndp != MODE_RELAY) return (iface ? NL_OK : NL_SKIP); nlmsg_parse(hdr, sizeof(*ndm), nla, __NDA_MAX - 1, NULL); diff --git a/src/odhcpd.c b/src/odhcpd.c index 5b739d0..837004b 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -566,7 +566,7 @@ static void odhcpd_receive_packets(struct uloop_fd *u, _unused unsigned int even { struct odhcpd_event *e = container_of(u, struct odhcpd_event, uloop); - uint8_t data_buf[RELAYD_BUFFER_SIZE], cmsg_buf[128]; + uint8_t data_buf[8192], cmsg_buf[128]; union { struct sockaddr_in6 in6; struct sockaddr_in in; diff --git a/src/odhcpd.h b/src/odhcpd.h index b0801a4..a240aa1 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -40,8 +40,6 @@ #define ND_OPT_RECURSIVE_DNS 25 #define ND_OPT_DNS_SEARCH 31 -#define RELAYD_BUFFER_SIZE 8192 - #define INFINITE_VALID(x) ((x) == 0) #define _unused __attribute__((unused)) @@ -87,10 +85,10 @@ struct odhcpd_ipaddr { }; enum odhcpd_mode { - RELAYD_DISABLED, - RELAYD_SERVER, - RELAYD_RELAY, - RELAYD_HYBRID + MODE_DISABLED, + MODE_SERVER, + MODE_RELAY, + MODE_HYBRID }; diff --git a/src/router.c b/src/router.c index cb2afc9..30f1609 100644 --- a/src/router.c +++ b/src/router.c @@ -113,15 +113,15 @@ int setup_router_interface(struct interface *iface, bool enable) } else { void *mreq = &all_routers; - if (iface->ra == RELAYD_RELAY && iface->master) { + if (iface->ra == MODE_RELAY && iface->master) { mreq = &all_nodes; forward_router_solicitation(iface); - } else if (iface->ra == RELAYD_SERVER && !iface->master) { + } else if (iface->ra == MODE_SERVER && !iface->master) { iface->timer_rs.cb = trigger_router_advert; uloop_timeout_set(&iface->timer_rs, 1000); } - if (iface->ra == RELAYD_RELAY || (iface->ra == RELAYD_SERVER && !iface->master)) + if (iface->ra == MODE_RELAY || (iface->ra == MODE_SERVER && !iface->master)) setsockopt(router_event.uloop.fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, mreq, sizeof(all_nodes)); } @@ -134,7 +134,7 @@ static void sigusr1_refresh(_unused int signal) { struct interface *iface; list_for_each_entry(iface, &interfaces, head) - if (iface->ra == RELAYD_SERVER && !iface->master) + if (iface->ra == MODE_SERVER && !iface->master) uloop_timeout_set(&iface->timer_rs, 1000); } @@ -584,10 +584,10 @@ static void handle_icmpv6(void *addr, void *data, size_t len, if (!router_icmpv6_valid(addr, data, len)) return; - if ((iface->ra == RELAYD_SERVER && !iface->master)) { // Server mode + if ((iface->ra == MODE_SERVER && !iface->master)) { // Server mode if (hdr->icmp6_type == ND_ROUTER_SOLICIT) send_router_advert(iface, &from->sin6_addr); - } else if (iface->ra == RELAYD_RELAY) { // Relay mode + } else if (iface->ra == MODE_RELAY) { // Relay mode if (hdr->icmp6_type == ND_ROUTER_ADVERT && iface->master) forward_router_advertisement(data, len); else if (hdr->icmp6_type == ND_ROUTER_SOLICIT && !iface->master) @@ -646,7 +646,7 @@ static void forward_router_advertisement(uint8_t *data, size_t len) struct interface *iface; list_for_each_entry(iface, &interfaces, head) { - if (iface->ra != RELAYD_RELAY || iface->master) + if (iface->ra != MODE_RELAY || iface->master) continue; // Fixup source hardware address option diff --git a/src/ubus.c b/src/ubus.c index 30f7e93..14d0c42 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -27,7 +27,7 @@ static int handle_dhcpv4_leases(struct ubus_context *ctx, _unused struct ubus_ob a = blobmsg_open_table(&b, "device"); list_for_each_entry(iface, &interfaces, head) { - if (iface->dhcpv4 != RELAYD_SERVER || iface->dhcpv4_assignments.next == NULL) + if (iface->dhcpv4 != MODE_SERVER || iface->dhcpv4_assignments.next == NULL) continue; void *i = blobmsg_open_table(&b, iface->ifname); @@ -106,7 +106,7 @@ static int handle_dhcpv6_leases(_unused struct ubus_context *ctx, _unused struct a = blobmsg_open_table(&b, "device"); list_for_each_entry(iface, &interfaces, head) { - if (iface->dhcpv6 != RELAYD_SERVER || iface->ia_assignments.next == NULL) + if (iface->dhcpv6 != MODE_SERVER || iface->ia_assignments.next == NULL) continue; void *i = blobmsg_open_table(&b, iface->ifname);