--- embedaddon/mpd/src/iface.c 2019/10/22 13:49:55 1.1.1.4 +++ embedaddon/mpd/src/iface.c 2021/03/17 00:39:23 1.1.1.5 @@ -19,6 +19,7 @@ #include "netgraph.h" #include "util.h" +#include #include #include #include @@ -98,9 +99,9 @@ static void IfaceNgIpv6Shutdown(Bund b); #ifdef USE_NG_NETFLOW - static int IfaceInitNetflow(Bund b, char *path, char *hook, char in, char out, int v6); + static int IfaceInitNetflow(Bund b, char *path, char *hook, char out, int v6); static int IfaceSetupNetflow(Bund b, char in, char out, int v6); - static void IfaceShutdownNetflow(Bund b, char in, char out, int v6); + static void IfaceShutdownNetflow(Bund b, char out, int v6); #endif #ifdef USE_NG_IPACCT @@ -129,7 +130,7 @@ static void IfaceShutdownLimits(Bund b); #endif - static int IfaceSetCommand(Context ctx, int ac, char *av[], void *arg); + static int IfaceSetCommand(Context ctx, int ac, const char *const av[], const void *arg); static void IfaceSessionTimeout(void *arg); static void IfaceIdleTimeout(void *arg); @@ -188,7 +189,7 @@ IfaceSetCommand, NULL, 2, (void *) SET_ENABLE }, { "disable [opt ...]", "Disable option", IfaceSetCommand, NULL, 2, (void *) SET_DISABLE }, - { NULL }, + { NULL, NULL, NULL, NULL, 0, NULL }, }; /* @@ -611,11 +612,11 @@ IfaceUp(Bund b, int ready) iface->tables = acl; if (strncmp(acl->rule, "peer_addr", 9) == 0) { char hisaddr[20]; - ExecCmd(LG_IFACE2, b->name, "%s table %d add %s", + ExecCmd(LG_IFACE2, b->name, "%s -q table %d add %s", PATH_IPFW, acl->real_number, u_addrtoa(&iface->peer_addr, hisaddr, sizeof(hisaddr))); } else { - ExecCmd(LG_IFACE2, b->name, "%s table %d add %s", PATH_IPFW, acl->real_number, acl->rule); + ExecCmd(LG_IFACE2, b->name, "%s -q table %d add %s", PATH_IPFW, acl->real_number, acl->rule); } acls = acls->next; }; @@ -650,7 +651,7 @@ IfaceDown(Bund b) IfaceState const iface = &b->iface; #ifdef USE_IPFW struct acl_pool **rp, *rp1; - char cb[32768]; + char cb[LINE_MAX - sizeof(PATH_IPFW) - 14]; struct acl *acl, *aclnext; #endif @@ -695,12 +696,12 @@ IfaceDown(Bund b) while (acl != NULL) { if (strncmp(acl->rule, "peer_addr", 9) == 0) { char hisaddr[20]; - ExecCmd(LG_IFACE2, b->name, "%s table %d delete %s", + ExecCmd(LG_IFACE2, b->name, "%s -q table %d delete %s", PATH_IPFW, acl->real_number, u_addrtoa(&iface->peer_addr, hisaddr, sizeof(hisaddr))); } else { char buf[ACL_LEN]; - ExecCmd(LG_IFACE2, b->name, "%s table %d delete %s", + ExecCmd(LG_IFACE2, b->name, "%s -q table %d delete %s", PATH_IPFW, acl->real_number, IfaceFixAclForDelete(acl->rule, buf, sizeof(buf))); } @@ -967,7 +968,7 @@ static char* IfaceFixAclForDelete(char *r, char *buf, size_t len) { static const char sep[] = " \t"; - char *limit, *s; + char *limit, *orig, *s; int i, state = 0; /* @@ -978,6 +979,7 @@ IfaceFixAclForDelete(char *r, char *buf, size_t len) * 1: not first iteration, do copy. */ + orig = r; s = buf; limit = buf + len; @@ -993,7 +995,7 @@ IfaceFixAclForDelete(char *r, char *buf, size_t len) continue; } if (limit - s < i + 1 + state) /* Check space. */ - return r; + return orig; if (state != 0) /* Insert separator. */ *s++ = ' '; memcpy(s, r, i); /* Copy IP address from the rule. */ @@ -1442,7 +1444,7 @@ IfaceIsDemand(int proto, Mbuf pkt) if (MBLEN(pkt) < sizeof(struct ip)) return (0); - ip = (struct ip *)MBDATA(pkt); + ip = (struct ip *)(void *)MBDATA(pkt); switch (ip->ip_p) { case IPPROTO_IGMP: /* No multicast stuff */ return(0); @@ -1454,7 +1456,7 @@ IfaceIsDemand(int proto, Mbuf pkt) if (MBLEN(pkt) < (ip->ip_hl * 4 + sizeof(struct icmphdr))) return (0); - icmp = (struct icmphdr *) ((u_int32_t *) ip + ip->ip_hl); + icmp = (struct icmphdr *) ((u_int32_t *)(void *) ip + ip->ip_hl); switch (icmp->icmp_type) /* No ICMP replies */ { @@ -1475,7 +1477,7 @@ IfaceIsDemand(int proto, Mbuf pkt) if (MBLEN(pkt) < (ip->ip_hl * 4 + sizeof(struct udphdr))) return (0); - udp = (struct udphdr *) ((u_int32_t *) ip + ip->ip_hl); + udp = (struct udphdr *) ((u_int32_t *)(void *) ip + ip->ip_hl); #define NTP_PORT 123 if (ntohs(udp->uh_dport) == NTP_PORT) /* No NTP packets */ @@ -1489,7 +1491,7 @@ IfaceIsDemand(int proto, Mbuf pkt) if (MBLEN(pkt) < (ip->ip_hl * 4 + sizeof(struct tcphdr))) return (0); - tcp = (struct tcphdr *) ((u_int32_t *) ip + ip->ip_hl); + tcp = (struct tcphdr *) ((u_int32_t *)(void *) ip + ip->ip_hl); if (tcp->th_flags & TH_RST) /* No TCP reset packets */ return(0); @@ -1511,7 +1513,7 @@ IfaceIsDemand(int proto, Mbuf pkt) */ static int -IfaceSetCommand(Context ctx, int ac, char *av[], void *arg) +IfaceSetCommand(Context ctx, int ac, const char *const av[], const void *arg) { IfaceState const iface = &ctx->bund->iface; int empty_arg; @@ -1544,24 +1546,24 @@ IfaceSetCommand(Context ctx, int ac, char *av[], void struct u_range self_addr; struct u_addr peer_addr; int self_addr_force = 0, peer_addr_force = 0; - char *arg; + const char *arg1; /* Parse */ if (ac != 2) return(-1); - arg = av[0]; - if (arg[0] == '!') { + arg1 = av[0]; + if (arg1[0] == '!') { self_addr_force = 1; - arg++; + arg1++; } - if (!ParseRange(arg, &self_addr, ALLOW_IPV4|ALLOW_IPV6)) + if (!ParseRange(arg1, &self_addr, ALLOW_IPV4|ALLOW_IPV6)) Error("Bad IP address \"%s\"", av[0]); - arg = av[1]; - if (arg[0] == '!') { + arg1 = av[1]; + if (arg1[0] == '!') { peer_addr_force = 1; - arg++; + arg1++; } - if (!ParseAddr(arg, &peer_addr, ALLOW_IPV4|ALLOW_IPV6)) + if (!ParseAddr(arg1, &peer_addr, ALLOW_IPV4|ALLOW_IPV6)) Error("Bad IP address \"%s\"", av[1]); if (self_addr.addr.family != peer_addr.family) Error("Addresses must be from the same protocol family"); @@ -1645,9 +1647,9 @@ IfaceSetCommand(Context ctx, int ac, char *av[], void break; case 1: if (strcmp(iface->ifname, av[0]) != 0) { - int ifmaxlen = IF_NAMESIZE - ctx->bund->tmpl * IFNUMLEN; + unsigned ifmaxlen = IF_NAMESIZE - ctx->bund->tmpl * IFNUMLEN; if (strlen(av[0]) >= ifmaxlen) - Error("Interface name too long, >%d characters", ifmaxlen-1); + Error("Interface name too long, >%u characters", ifmaxlen-1); if ((strncmp(av[0], "ng", 2) == 0) && ((ctx->bund->tmpl && av[0][2] == 0) || (av[0][2] >= '0' && av[0][2] <= '9'))) @@ -1736,7 +1738,7 @@ IfaceSetCommand(Context ctx, int ac, char *av[], void */ int -IfaceStat(Context ctx, int ac, char *av[], void *arg) +IfaceStat(Context ctx, int ac, const char *const av[], const void *arg) { Bund const b = ctx->bund; IfaceState const iface = &b->iface; @@ -1749,6 +1751,10 @@ IfaceStat(Context ctx, int ac, char *av[], void *arg) struct acl *a; #endif + (void)ac; + (void)av; + (void)arg; + Printf("Interface configuration:\r\n"); Printf("\tName : %s\r\n", iface->conf.ifname); #ifdef SIOCSIFDESCR @@ -1885,7 +1891,7 @@ IfaceSetMTU(Bund b, int mtu) int s; /* Get socket */ - if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { + if ((s = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0) { Perror("[%s] IFACE: Can't get socket to set MTU", b->name); return; } @@ -1934,7 +1940,7 @@ IfaceChangeFlags(Bund b, int clear, int set) Log(LG_IFACE2, ("[%s] IFACE: Change interface %s flags: -%d +%d", b->name, b->iface.ifname, clear, set)); - if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { + if ((s = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0) { Perror("[%s] IFACE: Can't get socket to change interface flags", b->name); return; } @@ -1942,7 +1948,7 @@ IfaceChangeFlags(Bund b, int clear, int set) memset(&ifrq, '\0', sizeof(ifrq)); strlcpy(ifrq.ifr_name, b->iface.ifname, sizeof(ifrq.ifr_name)); if (ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) { - Perror("[%s] IFACE: ioctl(SIOCGIFFLAGS, %s)", b->name, b->iface.ifname); + Perror("[%s] IFACE: ioctl(%s, %s)", b->name, b->iface.ifname, "SIOCGIFFLAGS"); close(s); return; } @@ -1955,7 +1961,7 @@ IfaceChangeFlags(Bund b, int clear, int set) ifrq.ifr_flagshigh = new_flags >> 16; if (ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) { - Perror("[%s] IFACE: ioctl(SIOCSIFFLAGS, %s)", b->name, b->iface.ifname); + Perror("[%s] IFACE: ioctl(%s, %s)", b->name, b->iface.ifname, "SIOCSIFFLAGS"); close(s); return; } @@ -1970,7 +1976,7 @@ add_scope(struct sockaddr *sa, int ifindex) if (sa->sa_family != AF_INET6) return; - sa6 = (struct sockaddr_in6 *)sa; + sa6 = (struct sockaddr_in6 *)(void *)sa; if (!IN6_IS_ADDR_LINKLOCAL(&sa6->sin6_addr) && !IN6_IS_ADDR_MC_LINKLOCAL(&sa6->sin6_addr)) return; @@ -2010,13 +2016,13 @@ IfaceChangeAddr(Bund b, int add, struct u_range *self, memset(&ifra, '\0', sizeof(ifra)); strlcpy(ifra.ifra_name, b->iface.ifname, sizeof(ifra.ifra_name)); - me4 = (struct sockaddr_in *)&ifra.ifra_addr; + me4 = (struct sockaddr_in *)(void *)&ifra.ifra_addr; memcpy(me4, &ssself, sizeof(*me4)); - msk4 = (struct sockaddr_in *)&ifra.ifra_mask; + msk4 = (struct sockaddr_in *)(void *)&ifra.ifra_mask; memcpy(msk4, &ssmsk, sizeof(*msk4)); - peer4 = (struct sockaddr_in *)&ifra.ifra_broadaddr; + peer4 = (struct sockaddr_in *)(void *)&ifra.ifra_broadaddr; if (peer == NULL || peer->family == AF_UNSPEC) { peer4->sin_family = AF_INET; peer4->sin_len = sizeof(*peer4); @@ -2167,10 +2173,10 @@ IfaceCorrectMSS(Mbuf pkt, uint16_t maxmss) if (pkt == NULL) return; - iphdr = (struct ip *)MBDATAU(pkt); + iphdr = (struct ip *)(void *)MBDATAU(pkt); hlen = iphdr->ip_hl << 2; pktlen = MBLEN(pkt) - hlen; - tc = (struct tcphdr *)(MBDATAU(pkt) + hlen); + tc = (struct tcphdr *)(void *)(MBDATAU(pkt) + hlen); hlen = tc->th_off << 2; /* Invalid header length or header without options. */ @@ -2194,7 +2200,7 @@ IfaceCorrectMSS(Mbuf pkt, uint16_t maxmss) if (*opt == TCPOPT_MAXSEG) { if (optlen != TCPOLEN_MAXSEG) continue; - mss = (u_int16_t *)(opt + 2); + mss = (u_int16_t *)(void *)(opt + 2); if (ntohs(*mss) > maxmss) { accumulate = *mss; *mss = htons(maxmss); @@ -2255,7 +2261,6 @@ IfaceNgIpInit(Bund b, int ready) if (Enabled(&b->iface.options, IFACE_CONF_NETFLOW_IN) || Enabled(&b->iface.options, IFACE_CONF_NETFLOW_OUT)) { if (IfaceInitNetflow(b, path, hook, - Enabled(&b->iface.options, IFACE_CONF_NETFLOW_IN)?1:0, Enabled(&b->iface.options, IFACE_CONF_NETFLOW_OUT)?1:0, 0)) goto fail; if (Enabled(&b->iface.options, IFACE_CONF_NETFLOW_IN)) @@ -2266,13 +2271,13 @@ IfaceNgIpInit(Bund b, int ready) #else /* NG_NETFLOW_CONF_INGRESS */ /* Connect a netflow node if configured */ if (Enabled(&b->iface.options, IFACE_CONF_NETFLOW_IN)) { - if (IfaceInitNetflow(b, path, hook, 1, 0, 0)) + if (IfaceInitNetflow(b, path, hook, 0, 0)) goto fail; b->iface.nfin_up = 1; } if (Enabled(&b->iface.options, IFACE_CONF_NETFLOW_OUT)) { - if (IfaceInitNetflow(b, path, hook, 0, 1, 0)) + if (IfaceInitNetflow(b, path, hook, 1, 0)) goto fail; b->iface.nfout_up = 1; } @@ -2360,15 +2365,15 @@ IfaceNgIpShutdown(Bund b) #ifdef USE_NG_NETFLOW #ifdef NG_NETFLOW_CONF_INGRESS if (b->iface.nfin_up || b->iface.nfout_up) - IfaceShutdownNetflow(b, b->iface.nfin_up, b->iface.nfout_up, 0); + IfaceShutdownNetflow(b, b->iface.nfout_up, 0); b->iface.nfin_up = 0; b->iface.nfout_up = 0; #else /* NG_NETFLOW_CONF_INGRESS */ if (b->iface.nfin_up) - IfaceShutdownNetflow(b, 1, 0, 0); + IfaceShutdownNetflow(b, 0, 0); b->iface.nfin_up = 0; if (b->iface.nfout_up) - IfaceShutdownNetflow(b, 0, 1, 0); + IfaceShutdownNetflow(b, 1, 0); b->iface.nfout_up = 0; #endif /* NG_NETFLOW_CONF_INGRESS */ #endif @@ -2419,7 +2424,6 @@ IfaceNgIpv6Init(Bund b, int ready) if (Enabled(&b->iface.options, IFACE_CONF_NETFLOW_IN) || Enabled(&b->iface.options, IFACE_CONF_NETFLOW_OUT)) { if (IfaceInitNetflow(b, path, hook, - Enabled(&b->iface.options, IFACE_CONF_NETFLOW_IN)?1:0, Enabled(&b->iface.options, IFACE_CONF_NETFLOW_OUT)?1:0, 1)) goto fail; if (Enabled(&b->iface.options, IFACE_CONF_NETFLOW_IN)) @@ -2430,13 +2434,13 @@ IfaceNgIpv6Init(Bund b, int ready) #else /* NG_NETFLOW_CONF_INGRESS */ /* Connect a netflow node if configured */ if (Enabled(&b->iface.options, IFACE_CONF_NETFLOW_IN)) { - if (IfaceInitNetflow(b, path, hook, 1, 0, 1)) + if (IfaceInitNetflow(b, path, hook, 0, 1)) goto fail; b->iface.nfin_up = 1; } if (Enabled(&b->iface.options, IFACE_CONF_NETFLOW_OUT)) { - if (IfaceInitNetflow(b, path, hook, 0, 1, 1)) + if (IfaceInitNetflow(b, path, hook, 1, 1)) goto fail; b->iface.nfout_up = 1; } @@ -2504,15 +2508,15 @@ IfaceNgIpv6Shutdown(Bund b) #ifdef USE_NG_NETFLOW #ifdef NG_NETFLOW_CONF_INGRESS if (b->iface.nfin_up || b->iface.nfout_up) - IfaceShutdownNetflow(b, b->iface.nfin_up, b->iface.nfout_up, 1); + IfaceShutdownNetflow(b, b->iface.nfout_up, 1); b->iface.nfin_up = 0; b->iface.nfout_up = 0; #else /* NG_NETFLOW_CONF_INGRESS */ if (b->iface.nfin_up) - IfaceShutdownNetflow(b, 1, 0, 1); + IfaceShutdownNetflow(b, 0, 1); b->iface.nfin_up = 0; if (b->iface.nfout_up) - IfaceShutdownNetflow(b, 0, 1, 1); + IfaceShutdownNetflow(b, 1, 1); b->iface.nfout_up = 0; #endif /* NG_NETFLOW_CONF_INGRESS */ #endif @@ -2841,7 +2845,7 @@ IfaceShutdownIpacct(Bund b) #ifdef USE_NG_NETFLOW static int -IfaceInitNetflow(Bund b, char *path, char *hook, char in, char out, int v6) +IfaceInitNetflow(Bund b, char *path, char *hook, char out, int v6) { struct ngm_connect cn; int nif; @@ -2955,13 +2959,14 @@ fail: } static void -IfaceShutdownNetflow(Bund b, char in, char out, int v6) +IfaceShutdownNetflow(Bund b, char out, int v6) { char path[NG_PATHSIZ]; char hook[NG_HOOKSIZ]; int nif; #ifdef NG_NETFLOW_CONF_INGRESS + (void)out; nif = gNetflowIface + b->id*2; #else nif = gNetflowIface + b->id*4 + out*2; @@ -3753,7 +3758,7 @@ IfaceSetName(Bund b, const char * ifname) return(0); /* Get socket */ - if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { + if ((s = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0) { Perror("[%s] IFACE: Can't get socket to set name", b->name); return(-1); } @@ -3761,13 +3766,22 @@ IfaceSetName(Bund b, const char * ifname) /* Set name of interface */ memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, iface->ifname, sizeof(ifr.ifr_name)); - ifr.ifr_data = (caddr_t)ifname; + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wcast-qual" +#endif + ifr.ifr_data = (char *)ifname; +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + Log(LG_IFACE2, ("[%s] IFACE: setting \"%s\" name to \"%s\"", b->name, iface->ifname, ifname)); if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) { if (errno != EEXIST) { - Perror("[%s] IFACE: ioctl(%s, SIOCSIFNAME)", b->name, iface->ifname); + Perror("[%s] IFACE: ioctl(%s, %s)", b->name, iface->ifname, "SIOCSIFNAME"); close(s); return(-1); } @@ -3826,7 +3840,7 @@ IfaceSetDescr(Bund b, const char * template) */ if (mib[0] < 0 && sysctlnametomib("net.ifdescr_maxlen", mib, &miblen) < 0) { mib[0] = 0; - Perror("[%s] IFACE: sysctl net.ifdescr_maxlen failed", b->name); + Perror("[%s] IFACE: sysctl net.ifdescr_maxlen failed", b->name); } /* @@ -3923,7 +3937,7 @@ IfaceSetDescr(Bund b, const char * template) /* peer MAC address */ case 'M': if (b->links[0]) { - PhysType const pt = b->links[0]->type; + const struct phystype * pt = b->links[0]->type; if (pt && pt->peermacaddr) { (*pt->peermacaddr)(b->links[0], buf, sizeof(buf)); DST_COPY(buf); @@ -3934,7 +3948,7 @@ IfaceSetDescr(Bund b, const char * template) DST_COPY("-"); } break; - /* local "physycal" address */ + /* local "physical" address */ case 'o': if (b->links[0] && PhysGetSelfAddr(b->links[0], buf, sizeof(buf)) == 0) { DST_COPY(buf); @@ -3942,7 +3956,7 @@ IfaceSetDescr(Bund b, const char * template) DST_COPY("-"); } break; - /* peer "physycal" address */ + /* peer "physical" address */ case 'O': if (b->links[0] && PhysGetPeerAddr(b->links[0], buf, sizeof(buf)) == 0) { DST_COPY(buf); @@ -4005,7 +4019,7 @@ IfaceSetDescr(Bund b, const char * template) return(0); /* we have not set system interface name yet */ /* Get socket */ - if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { + if ((s = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0) { Perror("[%s] IFACE: Can't get socket to set description for %s", b->name, ifname); return(-1); @@ -4058,7 +4072,7 @@ IfaceAddGroup(Bund b, const char * ifgroup) } /* Get socket */ - if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { + if ((s = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0) { Perror("[%s] IFACE: Can't get socket to add group", b->name); return(-1); } @@ -4073,7 +4087,7 @@ IfaceAddGroup(Bund b, const char * ifgroup) i = ioctl(s, SIOCAIFGROUP, (caddr_t)&ifgr); if (i < 0 && i != EEXIST) { - Perror("[%s] IFACE: ioctl(%s, SIOCAIFGROUP)", b->name, iface->ifname); + Perror("[%s] IFACE: ioctl(%s, %s)", b->name, iface->ifname, "SIOCAIFGROUP"); close(s); return(-1); } @@ -4093,7 +4107,7 @@ IfaceDelGroup(Bund b, const char * ifgroup) int s; /* Get socket */ - if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { + if ((s = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0) { Perror("[%s] IFACE: Can't get socket to delete from group", b->name); return(-1); } @@ -4112,7 +4126,7 @@ IfaceDelGroup(Bund b, const char * ifgroup) b->name, iface->ifname, ifgroup)); if (ioctl(s, SIOCDIFGROUP, (caddr_t)&ifgr) == -1) { - Perror("[%s] IFACE: ioctl(%s, SIOCDIFGROUP)", b->name, iface->ifname); + Perror("[%s] IFACE: ioctl(%s, %s)", b->name, iface->ifname, "SIOCDIFGROUP"); close(s); return(-1); }