From: Hans Dedecker Date: Mon, 28 May 2018 10:26:19 +0000 (+0200) Subject: treewide: switch to C-code style comments X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=029123bc5f2bd9429abc27c987e40af7799238a2;p=project%2Fodhcpd.git treewide: switch to C-code style comments Signed-off-by: Hans Dedecker --- diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 3002c1e..2a1d49f 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -623,7 +623,7 @@ static void dhcpv4_fr_stop(struct dhcpv4_assignment *a) a->fr_timer.cb = NULL; } -// Handler for DHCPv4 messages +/* Handler for DHCPv4 messages */ static void handle_dhcpv4(void *addr, void *data, size_t len, struct interface *iface, _unused void *dest_addr) { @@ -938,7 +938,7 @@ static bool dhcpv4_assign(struct interface *iface, uint32_t end = ntohl(iface->dhcpv4_end_ip.s_addr); uint32_t count = end - start + 1; - // try to assign the IP the client asked for + /* try to assign the IP the client asked for */ if (start <= ntohl(raddr) && ntohl(raddr) <= end && !find_assignment_by_addr(iface, raddr)) { assign->addr = raddr; @@ -950,10 +950,10 @@ static bool dhcpv4_assign(struct interface *iface, return true; } - // Seed RNG with checksum of hwaddress + /* Seed RNG with checksum of hwaddress */ uint32_t seed = 0; for (size_t i = 0; i < sizeof(assign->hwaddr); ++i) { - // Knuth's multiplicative method + /* Knuth's multiplicative method */ uint8_t o = assign->hwaddr[i]; seed += (o*2654435761) % UINT32_MAX; } diff --git a/src/dhcpv6.c b/src/dhcpv6.c index de3830d..4e7d0d0 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -34,7 +34,7 @@ static void handle_client_request(void *addr, void *data, size_t len, struct interface *iface, void *dest_addr); -// Create socket and register events +/* Create socket and register events */ int dhcpv6_init(void) { dhcpv6_ia_init(); @@ -51,7 +51,7 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable) iface->dhcpv6_event.uloop.fd = -1; } - // Configure multicast settings + /* Configure multicast settings */ if (enable && iface->dhcpv6) { struct sockaddr_in6 bind_addr = {AF_INET6, htons(DHCPV6_SERVER_PORT), 0, IN6ADDR_ANY_INIT, 0}; @@ -65,7 +65,7 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable) goto out; } - // Basic IPv6 configuration + /* Basic IPv6 configuration */ if (setsockopt(iface->dhcpv6_event.uloop.fd, SOL_SOCKET, SO_BINDTODEVICE, iface->ifname, strlen(iface->ifname)) < 0) { syslog(LOG_ERR, "setsockopt(SO_BINDTODEVICE): %m"); @@ -228,7 +228,7 @@ static void update_nested_message(uint8_t *data, size_t len, ssize_t pdiff) } } -// Simple DHCPv6-server for information requests +/* Simple DHCPv6-server for information requests */ static void handle_client_request(void *addr, void *data, size_t len, struct interface *iface, void *dest_addr) { @@ -239,7 +239,7 @@ static void handle_client_request(void *addr, void *data, size_t len, syslog(LOG_NOTICE, "Got DHCPv6 request"); - // Construct reply message + /* Construct reply message */ struct __attribute__((packed)) { uint8_t msg_type; uint8_t tr_id[3]; @@ -299,7 +299,7 @@ static void handle_client_request(void *addr, void *data, size_t len, - // DNS Search options + /* DNS Search options */ uint8_t search_buf[256], *search_domain = iface->search; size_t search_len = iface->search_len; @@ -362,11 +362,11 @@ static void handle_client_request(void *addr, void *data, size_t len, iov[IOV_REFRESH].iov_base = &refresh; iov[IOV_REFRESH].iov_len = sizeof(refresh); - // Return inf max rt option in reply to information request + /* Return inf max rt option in reply to information request */ maxrt.type = htons(DHCPV6_OPT_INF_MAX_RT); } - // Go through options and find what we need + /* Go through options and find what we need */ uint16_t otype, olen; uint8_t *odata; dhcpv6_for_each_option(opts, opts_end, otype, olen, odata) { @@ -377,13 +377,13 @@ static void handle_client_request(void *addr, void *data, size_t len, } else if (otype == DHCPV6_OPT_SERVERID) { if (olen != ntohs(dest.serverid_length) || memcmp(odata, &dest.duid_type, olen)) - return; // Not for us + return; /* Not for us */ } else if (iface->filter_class && otype == DHCPV6_OPT_USER_CLASS) { uint8_t *c = odata, *cend = &odata[olen]; for (; &c[2] <= cend && &c[2 + (c[0] << 8) + c[1]] <= cend; c = &c[2 + (c[0] << 8) + c[1]]) { size_t elen = strlen(iface->filter_class); if (((((size_t)c[0]) << 8) | c[1]) == elen && !memcmp(&c[2], iface->filter_class, elen)) - return; // Ignore from homenet + return; /* Ignore from homenet */ } } else if (otype == DHCPV6_OPT_IA_PD) { #ifdef EXT_CER_ID @@ -424,7 +424,7 @@ static void handle_client_request(void *addr, void *data, size_t len, return; } - if (iov[IOV_NESTED].iov_len > 0) // Update length + if (iov[IOV_NESTED].iov_len > 0) /* Update length */ update_nested_message(data, len, iov[IOV_DEST].iov_len + iov[IOV_MAXRT].iov_len + iov[IOV_DNS].iov_len + iov[IOV_DNS_ADDR].iov_len + iov[IOV_SEARCH].iov_len + iov[IOV_SEARCH_DOMAIN].iov_len + @@ -435,7 +435,7 @@ static void handle_client_request(void *addr, void *data, size_t len, } -// Central DHCPv6-relay handler +/* Central DHCPv6-relay handler */ static void handle_dhcpv6(void *addr, void *data, size_t len, struct interface *iface, void *dest_addr) { @@ -450,10 +450,10 @@ static void handle_dhcpv6(void *addr, void *data, size_t len, } -// Relay server response (regular relay server handling) +/* Relay server response (regular relay server handling) */ static void relay_server_response(uint8_t *data, size_t len) { - // Information we need to gather + /* Information we need to gather */ uint8_t *payload_data = NULL; size_t payload_len = 0; int32_t ifaceidx = 0; @@ -465,7 +465,7 @@ static void relay_server_response(uint8_t *data, size_t len) int otype, olen; uint8_t *odata, *end = data + len; - // Relay DHCPv6 reply from server to client + /* Relay DHCPv6 reply from server to client */ struct dhcpv6_relay_header *h = (void*)data; if (len < sizeof(*h) || h->msg_type != DHCPV6_MSG_RELAY_REPL) return; @@ -473,7 +473,7 @@ static void relay_server_response(uint8_t *data, size_t len) memcpy(&target.sin6_addr, &h->peer_address, sizeof(struct in6_addr)); - // Go through options and find what we need + /* Go through options and find what we need */ dhcpv6_for_each_option(h->options, end, otype, olen, odata) { if (otype == DHCPV6_OPT_INTERFACE_ID && olen == sizeof(ifaceidx)) { @@ -484,7 +484,7 @@ static void relay_server_response(uint8_t *data, size_t len) } } - // Invalid interface-id or basic payload + /* Invalid interface-id or basic payload */ struct interface *iface = odhcpd_get_interface_by_index(ifaceidx); if (!iface || iface->master || !payload_data || payload_len < 4) return; @@ -493,10 +493,10 @@ static void relay_server_response(uint8_t *data, size_t len) struct in6_addr *dns_ptr = NULL; size_t dns_count = 0; - // If the payload is relay-reply we have to send to the server port + /* If the payload is relay-reply we have to send to the server port */ if (payload_data[0] == DHCPV6_MSG_RELAY_REPL) { target.sin6_port = htons(DHCPV6_SERVER_PORT); - } else { // Go through the payload data + } else { /* Go through the payload data */ struct dhcpv6_client_header *h = (void*)payload_data; end = payload_data + payload_len; @@ -510,10 +510,10 @@ static void relay_server_response(uint8_t *data, size_t len) } } - // Rewrite DNS servers if requested + /* Rewrite DNS servers if requested */ if (iface->always_rewrite_dns && dns_ptr && dns_count > 0) { if (is_authenticated) - return; // Impossible to rewrite + return; /* Impossible to rewrite */ const struct in6_addr *rewrite = iface->dns; struct in6_addr addr; @@ -527,7 +527,7 @@ static void relay_server_response(uint8_t *data, size_t len) rewrite_cnt = 1; } - // Copy over any other addresses + /* Copy over any other addresses */ for (size_t i = 0; i < dns_count; ++i) { size_t j = (i < rewrite_cnt) ? i : rewrite_cnt - 1; memcpy(&dns_ptr[i], &rewrite[j], sizeof(*rewrite)); @@ -559,7 +559,7 @@ static struct odhcpd_ipaddr *relay_link_address(struct interface *iface) return addr; } -// Relay client request (regular DHCPv6-relay) +/* Relay client request (regular DHCPv6-relay) */ static void relay_client_request(struct sockaddr_in6 *source, const void *data, size_t len, struct interface *iface) { @@ -572,11 +572,11 @@ static void relay_client_request(struct sockaddr_in6 *source, h->msg_type == DHCPV6_MSG_RECONFIGURE || h->msg_type == DHCPV6_MSG_REPLY || h->msg_type == DHCPV6_MSG_ADVERTISE) - return; // Invalid message types for client + return; /* Invalid message types for client */ syslog(LOG_NOTICE, "Got a DHCPv6-request"); - // Construct our forwarding envelope + /* Construct our forwarding envelope */ struct dhcpv6_relay_forward_envelope hdr = { .msg_type = DHCPV6_MSG_RELAY_FORW, .hop_count = 0, @@ -586,29 +586,29 @@ static void relay_client_request(struct sockaddr_in6 *source, .relay_message_len = htons(len), }; - if (h->msg_type == DHCPV6_MSG_RELAY_FORW) { // handle relay-forward + if (h->msg_type == DHCPV6_MSG_RELAY_FORW) { /* handle relay-forward */ if (h->hop_count >= DHCPV6_HOP_COUNT_LIMIT) return; // Invalid hop count else hdr.hop_count = h->hop_count + 1; } - // use memcpy here as the destination fields are unaligned + /* use memcpy here as the destination fields are unaligned */ uint32_t ifindex = iface->ifindex; memcpy(&hdr.peer_address, &source->sin6_addr, sizeof(struct in6_addr)); memcpy(&hdr.interface_id_data, &ifindex, sizeof(ifindex)); - // Detect public IP of slave interface to use as link-address + /* Detect public IP of slave interface to use as link-address */ struct odhcpd_ipaddr *ip = relay_link_address(iface); if (!ip) { - // No suitable address! Is the slave not configured yet? - // Detect public IP of master interface and use it instead - // This is WRONG and probably violates the RFC. However - // otherwise we have a hen and egg problem because the - // slave-interface cannot be auto-configured. + /* No suitable address! Is the slave not configured yet? + * Detect public IP of master interface and use it instead + * This is WRONG and probably violates the RFC. However + * otherwise we have a hen and egg problem because the + * slave-interface cannot be auto-configured. */ ip = relay_link_address(master); if (!ip) - return; // Could not obtain a suitable address + return; /* Could not obtain a suitable address */ } memcpy(&hdr.link_address, &ip->addr.in6, sizeof(hdr.link_address)); diff --git a/src/ndp.c b/src/ndp.c index 6021db9..28aaa66 100644 --- a/src/ndp.c +++ b/src/ndp.c @@ -41,7 +41,7 @@ static void handle_solicit(void *addr, void *data, size_t len, static int ping_socket = -1; -// Filter ICMPv6 messages of type neighbor soliciation +/* Filter ICMPv6 messages of type neighbor soliciation */ static struct sock_filter bpf[] = { BPF_STMT(BPF_LD | BPF_B | BPF_ABS, offsetof(struct ip6_hdr, ip6_nxt)), BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, IPPROTO_ICMPV6, 0, 3), @@ -54,13 +54,13 @@ static struct sock_filter bpf[] = { static const struct sock_fprog bpf_prog = {sizeof(bpf) / sizeof(*bpf), bpf}; static struct netevent_handler ndp_netevent_handler = { .cb = ndp_netevent_cb, }; -// Initialize NDP-proxy +/* Initialize NDP-proxy */ int ndp_init(void) { struct icmp6_filter filt; int val = 2, ret = 0; - // Open ICMPv6 socket + /* Open ICMPv6 socket */ ping_socket = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6); if (ping_socket < 0) { syslog(LOG_ERR, "socket(AF_INET6): %m"); @@ -75,7 +75,7 @@ int ndp_init(void) goto out; } - // This is required by RFC 4861 + /* This is required by RFC 4861 */ val = 255; if (setsockopt(ping_socket, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &val, sizeof(val)) < 0) { @@ -91,7 +91,7 @@ int ndp_init(void) goto out; } - // Filter all packages, we only want to send + /* Filter all packages, we only want to send */ ICMP6_FILTER_SETBLOCKALL(&filt); if (setsockopt(ping_socket, IPPROTO_ICMPV6, ICMP6_FILTER, &filt, sizeof(filt)) < 0) { @@ -192,7 +192,7 @@ int ndp_setup_interface(struct interface *iface, bool enable) iface->ndp_event.handle_dgram = handle_solicit; odhcpd_register(&iface->ndp_event); - // If we already were enabled dump is unnecessary, if not do dump + /* If we already were enabled dump is unnecessary, if not do dump */ if (!dump_neigh) netlink_dump_neigh_table(false); else @@ -259,8 +259,8 @@ static void ndp_netevent_cb(unsigned long event, struct netevent_handler_info *i } } -// Send an ICMP-ECHO. This is less for actually pinging but for the -// neighbor cache to be kept up-to-date. +/* Send an ICMP-ECHO. This is less for actually pinging but for the + * neighbor cache to be kept up-to-date. */ static void ping6(struct in6_addr *addr, const struct interface *iface) { @@ -277,7 +277,7 @@ static void ping6(struct in6_addr *addr, netlink_setup_route(addr, 128, iface->ifindex, NULL, 128, false); } -// Handle solicitations +/* Handle solicitations */ static void handle_solicit(void *addr, void *data, size_t len, struct interface *iface, _unused void *dest) { @@ -287,12 +287,12 @@ static void handle_solicit(void *addr, void *data, size_t len, char ipbuf[INET6_ADDRSTRLEN]; uint8_t mac[6]; - // Solicitation is for duplicate address detection + /* Solicitation is for duplicate address detection */ bool ns_is_dad = IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src); - // 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 + /* 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 != MODE_RELAY || (iface->external && !ns_is_dad)) return; @@ -302,14 +302,14 @@ static void handle_solicit(void *addr, void *data, size_t len, if (IN6_IS_ADDR_LINKLOCAL(&req->nd_ns_target) || IN6_IS_ADDR_LOOPBACK(&req->nd_ns_target) || IN6_IS_ADDR_MULTICAST(&req->nd_ns_target)) - return; // Invalid target + return; /* Invalid target */ inet_ntop(AF_INET6, &req->nd_ns_target, ipbuf, sizeof(ipbuf)); syslog(LOG_DEBUG, "Got a NS for %s%%%s", ipbuf, iface->ifname); odhcpd_get_mac(iface, mac); if (!memcmp(ll->sll_addr, mac, sizeof(mac))) - return; // Looped back + return; /* Looped back */ struct interface *c; list_for_each_entry(c, &interfaces, head) @@ -318,7 +318,7 @@ static void handle_solicit(void *addr, void *data, size_t len, ping6(&req->nd_ns_target, c); } -// Use rtnetlink to modify kernel routes +/* Use rtnetlink to modify kernel routes */ static void setup_route(struct in6_addr *addr, struct interface *iface, bool add) { char ipbuf[INET6_ADDRSTRLEN]; diff --git a/src/netlink.c b/src/netlink.c index 56d35df..d238604 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -78,7 +78,7 @@ int netlink_init(void) nl_socket_modify_cb(rtnl_event.sock, NL_CB_VALID, NL_CB_CUSTOM, cb_rtnl_valid, NULL); - // Receive IPv4 address, IPv6 address, IPv6 routes and neighbor events + /* Receive IPv4 address, IPv6 address, IPv6 routes and neighbor events */ if (nl_socket_add_memberships(rtnl_event.sock, RTNLGRP_IPV4_IFADDR, RTNLGRP_IPV6_IFADDR, RTNLGRP_IPV6_ROUTE, RTNLGRP_NEIGH, RTNLGRP_LINK, 0)) @@ -184,8 +184,8 @@ static void refresh_iface_addr6(struct netevent_handler_info *event_info) free(event_info->addrs_old.addrs); } -// Handler for neighbor cache entries from the kernel. This is our source -// to learn and unlearn hosts on interfaces. +/* Handler for neighbor cache entries from the kernel. This is our source + * to learn and unlearn hosts on interfaces. */ static int cb_rtnl_valid(struct nl_msg *msg, _unused void *arg) { struct nlmsghdr *hdr = nlmsg_hdr(msg); @@ -500,7 +500,7 @@ static int prefix_cmp(const void *va, const void *vb) } -// compare IPv6 prefixes +/* compare IPv6 prefixes */ static int prefix6_cmp(const void *va, const void *vb) { const struct odhcpd_ipaddr *a = va, *b = vb; @@ -510,7 +510,7 @@ static int prefix6_cmp(const void *va, const void *vb) } -// Detect an IPV6-address currently assigned to the given interface +/* Detect an IPV6-address currently assigned to the given interface */ ssize_t netlink_get_interface_addrs(int ifindex, bool v6, struct odhcpd_ipaddr **addrs) { struct nl_msg *msg; diff --git a/src/odhcpd.c b/src/odhcpd.c index 2c6ae46..0e0002d 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -120,7 +120,7 @@ int main(int argc, char **argv) } -// Read IPv6 MTU for interface +/* Read IPv6 MTU for interface */ int odhcpd_get_interface_config(const char *ifname, const char *what) { char buf[64]; @@ -139,7 +139,7 @@ int odhcpd_get_interface_config(const char *ifname, const char *what) } -// Read IPv6 MAC for interface +/* Read IPv6 MAC for interface */ int odhcpd_get_mac(const struct interface *iface, uint8_t mac[6]) { struct ifreq ifr; @@ -154,12 +154,12 @@ int odhcpd_get_mac(const struct interface *iface, uint8_t mac[6]) } -// Forwards a packet on a specific interface +/* Forwards a packet on a specific interface */ ssize_t odhcpd_send(int socket, struct sockaddr_in6 *dest, struct iovec *iov, size_t iov_len, const struct interface *iface) { - // Construct headers + /* Construct headers */ uint8_t cmsg_buf[CMSG_SPACE(sizeof(struct in6_pktinfo))] = {0}; struct msghdr msg = { .msg_name = (void *) dest, @@ -171,7 +171,7 @@ ssize_t odhcpd_send(int socket, struct sockaddr_in6 *dest, .msg_flags = 0 }; - // Set control data (define destination interface) + /* Set control data (define destination interface) */ struct cmsghdr *chdr = CMSG_FIRSTHDR(&msg); chdr->cmsg_level = IPPROTO_IPV6; chdr->cmsg_type = IPV6_PKTINFO; @@ -179,7 +179,7 @@ ssize_t odhcpd_send(int socket, struct sockaddr_in6 *dest, struct in6_pktinfo *pktinfo = (struct in6_pktinfo*)CMSG_DATA(chdr); pktinfo->ipi6_ifindex = iface->ifindex; - // Also set scope ID if link-local + /* Also set scope ID if link-local */ if (IN6_IS_ADDR_LINKLOCAL(&dest->sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&dest->sin6_addr)) dest->sin6_scope_id = iface->ifindex; @@ -301,7 +301,7 @@ struct interface* odhcpd_get_master_interface(void) } -// Convenience function to receive and do basic validation of packets +/* Convenience function to receive and do basic validation of packets */ static void odhcpd_receive_packets(struct uloop_fd *u, _unused unsigned int events) { struct odhcpd_event *e = container_of(u, struct odhcpd_event, uloop); @@ -349,7 +349,7 @@ static void odhcpd_receive_packets(struct uloop_fd *u, _unused unsigned int even } - // Extract destination interface + /* Extract destination interface */ int destiface = 0; int *hlim = NULL; void *dest = NULL; @@ -372,11 +372,11 @@ static void odhcpd_receive_packets(struct uloop_fd *u, _unused unsigned int even } } - // Check hoplimit if received + /* Check hoplimit if received */ if (hlim && *hlim != 255) continue; - // Detect interface for packet sockets + /* Detect interface for packet sockets */ if (addr.ll.sll_family == AF_PACKET) destiface = addr.ll.sll_ifindex; @@ -389,7 +389,7 @@ static void odhcpd_receive_packets(struct uloop_fd *u, _unused unsigned int even else if (addr.in.sin_family == AF_INET) inet_ntop(AF_INET, &addr.in.sin_addr, ipbuf, sizeof(ipbuf)); - // From netlink + /* From netlink */ if (addr.nl.nl_family == AF_NETLINK) { syslog(LOG_DEBUG, "Received %li Bytes from %s%%%s", (long)len, ipbuf, "netlink"); @@ -412,7 +412,7 @@ static void odhcpd_receive_packets(struct uloop_fd *u, _unused unsigned int even } } -// Register events for the multiplexer +/* Register events for the multiplexer */ int odhcpd_register(struct odhcpd_event *event) { event->uloop.cb = odhcpd_receive_packets; diff --git a/src/router.c b/src/router.c index e52fffd..777cbc0 100644 --- a/src/router.c +++ b/src/router.c @@ -48,7 +48,7 @@ int router_init(void) struct icmp6_filter filt; int ret = 0; - // Open ICMPv6 socket + /* Open ICMPv6 socket */ router_event.uloop.fd = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6); if (router_event.uloop.fd < 0) { syslog(LOG_ERR, "socket(AF_INET6): %m"); @@ -56,7 +56,7 @@ int router_init(void) goto out; } - // Let the kernel compute our checksums + /* Let the kernel compute our checksums */ int val = 2; if (setsockopt(router_event.uloop.fd, IPPROTO_RAW, IPV6_CHECKSUM, &val, sizeof(val)) < 0) { @@ -65,7 +65,7 @@ int router_init(void) goto out; } - // This is required by RFC 4861 + /* This is required by RFC 4861 */ val = 255; if (setsockopt(router_event.uloop.fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &val, sizeof(val)) < 0) { @@ -81,7 +81,7 @@ int router_init(void) goto out; } - // We need to know the source interface + /* We need to know the source interface */ val = 1; if (setsockopt(router_event.uloop.fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &val, sizeof(val)) < 0) { @@ -97,7 +97,7 @@ int router_init(void) goto out; } - // Don't loop back + /* Don't loop back */ val = 0; if (setsockopt(router_event.uloop.fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &val, sizeof(val)) < 0) { @@ -106,7 +106,7 @@ int router_init(void) goto out; } - // Filter ICMPv6 package types + /* Filter ICMPv6 package types */ ICMP6_FILTER_SETBLOCKALL(&filt); ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt); ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filt); @@ -129,7 +129,7 @@ int router_init(void) goto out; } - // Register socket + /* Register socket */ odhcpd_register(&router_event); out: if (ret < 0) { @@ -253,12 +253,12 @@ static bool router_icmpv6_valid(struct sockaddr_in6 *source, uint8_t *data, size hdr->icmp6_type == ND_ROUTER_SOLICIT) return false; - // Check all options parsed successfully + /* Check all options parsed successfully */ return opt == end; } -// Detect whether a default route exists, also find the source prefixes +/* Detect whether a default route exists, also find the source prefixes */ static bool parse_routes(struct odhcpd_ipaddr *n, ssize_t len) { rewind(fp_route); @@ -350,7 +350,7 @@ enum { IOV_RA_TOTAL, }; -// Router Advert server mode +/* Router Advert server mode */ static uint64_t send_router_advert(struct interface *iface, const struct in6_addr *from) { time_t now = odhcpd_time(); @@ -396,14 +396,14 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add odhcpd_get_mac(iface, adv.lladdr.data); - // If not currently shutting down + /* If not currently shutting down */ struct odhcpd_ipaddr *addrs = NULL; ssize_t ipcnt = 0; uint32_t minvalid = UINT32_MAX; bool default_route = false; bool valid_prefix = false; - // If not shutdown + /* If not shutdown */ if (iface->timer_rs.cb) { size_t size = sizeof(*addrs) * iface->addr6_len; addrs = alloca(size); @@ -411,7 +411,7 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add ipcnt = iface->addr6_len; - // Check default route + /* Check default route */ if (iface->default_router) { default_route = true; @@ -427,7 +427,7 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add odhcpd_get_interface_dns_addr(iface, &dns_pref); - // Construct Prefix Information options + /* Construct Prefix Information options */ size_t pfxs_cnt = 0; struct nd_opt_prefix_info *pfxs = NULL; @@ -506,7 +506,7 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add p->nd_opt_pi_valid_time = htonl(valid); } - // Calculate periodic transmit + /* Calculate periodic transmit */ uint32_t maxival; int msecs = calc_adv_interval(iface, minvalid, &maxival); @@ -523,7 +523,7 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add syslog(LOG_INFO, "Using a RA lifetime of %d seconds on %s", ntohs(adv.h.nd_ra_router_lifetime), iface->ifname); - // DNS Recursive DNS + /* DNS Recursive DNS */ if (iface->dns_cnt > 0) { dns_addr = iface->dns; dns_cnt = iface->dns_cnt; @@ -540,7 +540,7 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add uint32_t lifetime; } dns = {ND_OPT_RECURSIVE_DNS, (1 + (2 * dns_cnt)), 0, 0, 0}; - // DNS Search options + /* DNS Search options */ uint8_t search_buf[256], *search_domain = iface->search; size_t search_len = iface->search_len, search_padded = 0; @@ -663,13 +663,13 @@ static void trigger_router_advert(struct uloop_timeout *event) struct interface *iface = container_of(event, struct interface, timer_rs); int msecs = send_router_advert(iface, NULL); - // Rearm timer if not shut down + /* Rearm timer if not shut down */ if (event->cb) uloop_timeout_set(event, msecs); } -// Event handler for incoming ICMPv6 packets +/* Event handler for incoming ICMPv6 packets */ static void handle_icmpv6(void *addr, void *data, size_t len, struct interface *iface, _unused void *dest) { @@ -679,10 +679,10 @@ static void handle_icmpv6(void *addr, void *data, size_t len, if (!router_icmpv6_valid(addr, data, len)) return; - if ((iface->ra == MODE_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 == MODE_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) @@ -691,7 +691,7 @@ static void handle_icmpv6(void *addr, void *data, size_t len, } -// Forward router solicitation +/* Forward router solicitation */ static void forward_router_solicitation(const struct interface *iface) { struct icmp6_hdr rs = {ND_ROUTER_SOLICIT, 0, 0, {{0}}}; @@ -711,13 +711,13 @@ static void forward_router_solicitation(const struct interface *iface) } -// Handler for incoming router solicitations on slave interfaces +/* Handler for incoming router solicitations on slave interfaces */ static void forward_router_advertisement(uint8_t *data, size_t len) { struct nd_router_advert *adv = (struct nd_router_advert *)data; struct sockaddr_in6 all_nodes; - // Rewrite options + /* Rewrite options */ uint8_t *end = data + len; uint8_t *mac_ptr = NULL; struct in6_addr *dns_ptr = NULL; @@ -726,10 +726,10 @@ static void forward_router_advertisement(uint8_t *data, size_t len) struct icmpv6_opt *opt; icmpv6_for_each_option(opt, &adv[1], end) { if (opt->type == ND_OPT_SOURCE_LINKADDR) { - // Store address of source MAC-address + /* Store address of source MAC-address */ mac_ptr = opt->data; } else if (opt->type == ND_OPT_RECURSIVE_DNS && opt->len > 1) { - // Check if we have to rewrite DNS + /* Check if we have to rewrite DNS */ dns_ptr = (struct in6_addr*)&opt->data[6]; dns_count = (opt->len - 1) / 2; } @@ -737,10 +737,10 @@ static void forward_router_advertisement(uint8_t *data, size_t len) syslog(LOG_NOTICE, "Got a RA"); - // Indicate a proxy, however we don't follow the rest of RFC 4389 yet + /* Indicate a proxy, however we don't follow the rest of RFC 4389 yet */ adv->nd_ra_flags_reserved |= ND_RA_FLAG_PROXY; - // Forward advertisement to all slave interfaces + /* Forward advertisement to all slave interfaces */ memset(&all_nodes, 0, sizeof(all_nodes)); all_nodes.sin6_family = AF_INET6; inet_pton(AF_INET6, ALL_IPV6_NODES, &all_nodes.sin6_addr); @@ -752,11 +752,11 @@ static void forward_router_advertisement(uint8_t *data, size_t len) if (iface->ra != MODE_RELAY || iface->master) continue; - // Fixup source hardware address option + /* Fixup source hardware address option */ if (mac_ptr) odhcpd_get_mac(iface, mac_ptr); - // If we have to rewrite DNS entries + /* If we have to rewrite DNS entries */ if (iface->always_rewrite_dns && dns_ptr && dns_count > 0) { const struct in6_addr *rewrite = iface->dns; struct in6_addr addr; @@ -764,13 +764,13 @@ static void forward_router_advertisement(uint8_t *data, size_t len) if (rewrite_cnt == 0) { if (odhcpd_get_interface_dns_addr(iface, &addr)) - continue; // Unable to comply + continue; /* Unable to comply */ rewrite = &addr; rewrite_cnt = 1; } - // Copy over any other addresses + /* Copy over any other addresses */ for (size_t i = 0; i < dns_count; ++i) { size_t j = (i < rewrite_cnt) ? i : rewrite_cnt - 1; dns_ptr[i] = rewrite[j];