--- embedaddon/mpd/src/pppoe.c 2019/10/22 13:49:55 1.1.1.4 +++ embedaddon/mpd/src/pppoe.c 2021/03/17 00:39:23 1.1.1.5 @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -157,7 +158,7 @@ static u_short PppoeGetMru(Link l, int conf); static void PppoeCtrlReadEvent(int type, void *arg); static void PppoeConnectTimeout(void *arg); static void PppoeStat(Context ctx); -static int PppoeSetCommand(Context ctx, int ac, char *av[], void *arg); +static int PppoeSetCommand(Context ctx, int ac, const char *const av[], const void *arg); static int PppoeOriginated(Link l); static int PppoeIsSync(Link l); static void PppoeGetNode(Link l); @@ -213,7 +214,7 @@ const struct cmdtab PppoeSetCmds[] = { #endif { "mac-format {format}", "Set RADIUS attribute 31 MAC format", PppoeSetCommand, NULL, 2, (void *)SET_MAC_FORMAT }, - { NULL } + { NULL, NULL, NULL, NULL, 0, NULL } }; /* @@ -237,8 +238,7 @@ struct PppoeIf { SLIST_HEAD(, PppoeList) list; }; -int PppoeIfCount=0; -struct PppoeIf PppoeIfs[PPPOE_MAXPARENTIFS]; +static struct PppoeIf PppoeIfs[PPPOE_MAXPARENTIFS]; struct tagname { int tag; @@ -552,7 +552,8 @@ PppoeCtrlReadEvent(int type, void *arg) PppoeInfo pi = NULL; struct PppoeIf *PIf = (struct PppoeIf*)arg; - + + (void)type; /* Read control message. */ if (NgRecvMsg(PIf->csock, &u.resp, sizeof(u), path) < 0) { Perror("PPPoE: error reading message from \"%s\"", path); @@ -645,7 +646,7 @@ PppoeCtrlReadEvent(int type, void *arg) { struct ngpppoe_maxp *maxp; - maxp = ((struct ngpppoe_maxp *)u.resp.data); + maxp = ((struct ngpppoe_maxp *)(void *)u.resp.data); Log(LG_PHYS, ("[%s] PPPoE: rec'd PPP-Max-Payload '%u'", l->name, maxp->data)); if (pi->max_payload > 0) { @@ -745,6 +746,7 @@ PppoeOriginated(Link l) static int PppoeIsSync(Link l) { + (void)l; return (1); } @@ -753,6 +755,8 @@ PppoePeerMacAddr(Link l, void *buf, size_t buf_len) { PppoeInfo const pppoe = (PppoeInfo)l->info; + if (buf_len < 18) + return (1); ether_ntoa_r((struct ether_addr *)pppoe->peeraddr, buf); return (0); } @@ -901,16 +905,14 @@ CreatePppoeNode(struct PppoeIf *PIf, const char *iface uint32_t f; /* Make sure interface is up. */ - if (ExecCmdNosh(LG_PHYS2, iface, "%s %s up", _PATH_IFCONFIG, iface) != 0) { - Log(LG_ERR, ("PPPoE: can't bring up interface %s", - iface)); + if (IfaceSetFlag(iface, IFF_UP) != 0) { + Perror("[%s] PPPoE: can't bring up interface", iface); return (0); } - /* Create a new netgraph node */ if (NgMkSockNode(NULL, &PIf->csock, &PIf->dsock) < 0) { Perror("[%s] PPPoE: can't create ctrl socket", iface); - return(0); + return (0); } (void)fcntl(PIf->csock, F_SETFD, 1); (void)fcntl(PIf->dsock, F_SETFD, 1); @@ -940,7 +942,7 @@ CreatePppoeNode(struct PppoeIf *PIf, const char *iface } /* Look for NG_ETHER_NODE_TYPE. */ - tlist = (const struct typelist*) resp->data; + tlist = (const struct typelist*)(void *)resp->data; for (f = 0; f < tlist->numtypes; f++) if (strncmp(tlist->typeinfo[f].type_name, NG_ETHER_NODE_TYPE, @@ -979,7 +981,7 @@ CreatePppoeNode(struct PppoeIf *PIf, const char *iface return (0); } - hlist = (const struct hooklist *)resp->data; + hlist = (const struct hooklist *)(void *)resp->data; ninfo = &hlist->nodeinfo; /* Make sure we've got the right type of node. */ @@ -1040,7 +1042,8 @@ CreatePppoeNode(struct PppoeIf *PIf, const char *iface snprintf(path2, sizeof(path2), "%s%s", path, hook); /* Get pppoe node ID */ if ((PIf->node_id = NgGetNodeID(PIf->csock, path2)) == 0) { - Perror("[%s] Cannot get pppoe node id", iface); + Perror("[%s] Cannot get %s node id", iface, + NG_PPPOE_NODE_TYPE); close(PIf->csock); close(PIf->dsock); return (0); @@ -1108,7 +1111,7 @@ get_vs_tag(const struct pppoe_hdr* ph, uint32_t idx) return (NULL); if (pt->tag_type == PTT_VENDOR && ntohs(pt->tag_len) >= 4 && - *(const uint32_t*)(pt + 1) == idx) + *(const uint32_t*)(const void *)(pt + 1) == idx) return (pt); pt = (const struct pppoe_tag*)ptn; @@ -1167,7 +1170,7 @@ print_tags(const struct pppoe_hdr* ph) break; case PTT_VENDOR: if (len >= 4) { - if ((uint8_t)*(uint8_t*)v != 0) { + if ((const uint8_t)*(const uint8_t*)v != 0) { snprintf(buf, sizeof(buf), "First byte of VENDOR is not zero! 0x%s", Bin2Hex(v, len)); @@ -1184,7 +1187,7 @@ print_tags(const struct pppoe_hdr* ph) if (len != 2) { sprintf(buf, "TAG_LENGTH is not 2!"); } else { - sprintf(buf, "%u", *(uint16_t*)(pt + 1)); + sprintf(buf, "%u", *(const uint16_t*)(const void *)(pt + 1)); } break; case PTT_SRV_ERR: @@ -1255,6 +1258,7 @@ PppoeListenEvent(int type, void *arg) } u; struct ngpppoe_init_data *const idata = &u.poeid; + (void)type; switch (sz = NgRecvData(PIf->dsock, response, sizeof(response), rhook)) { case -1: Log(LG_ERR, ("NgRecvData: %d", sz)); @@ -1271,7 +1275,7 @@ PppoeListenEvent(int type, void *arg) session = rhook + 7; - if (sz < sizeof(struct pppoe_full_hdr)) { + if ((size_t)sz < sizeof(struct pppoe_full_hdr)) { Log(LG_PHYS, ("Incoming truncated PPPoE connection request via %s for " "service \"%s\"", PIf->ifnodepath, session)); return; @@ -1280,7 +1284,7 @@ PppoeListenEvent(int type, void *arg) wh = (struct pppoe_full_hdr *)response; ph = &wh->ph; if ((tag = get_tag(ph, PTT_SRV_NAME))) { - int len = ntohs(tag->tag_len); + size_t len = ntohs(tag->tag_len); if (len >= sizeof(real_session)) len = sizeof(real_session)-1; memcpy(real_session, tag + 1, len); @@ -1291,10 +1295,10 @@ PppoeListenEvent(int type, void *arg) bzero(agent_cid, sizeof(agent_cid)); bzero(agent_rid, sizeof(agent_rid)); if ((tag = get_vs_tag(ph, htonl(0x00000DE9)))) { - int len = ntohs(tag->tag_len) - 4, pos = 0; + size_t len = ntohs(tag->tag_len) - 4, pos = 0; const char *b = (const char *)(tag + 1) + 4; while (pos + 1 <= len) { - int len1 = b[pos + 1]; + size_t len1 = b[pos + 1]; if (len1 > len - pos - 2) break; if (len1 >= sizeof(agent_rid)) @@ -1313,7 +1317,7 @@ PppoeListenEvent(int type, void *arg) Log(LG_PHYS, ("Incoming PPPoE connection request via %s for " "service \"%s\" from %s", PIf->ifnodepath, real_session, - ether_ntoa((struct ether_addr *)&wh->eh.ether_shost))); + ether_ntoa((const struct ether_addr *)&wh->eh.ether_shost))); if (gLogOptions & LG_PHYS3) print_tags(ph); @@ -1673,7 +1677,7 @@ PppoeNodeUpdate(Link l) */ static int -PppoeSetCommand(Context ctx, int ac, char *av[], void *arg) +PppoeSetCommand(Context ctx, int ac, const char *const av[], const void *arg) { const PppoeInfo pi = (PppoeInfo) ctx->lnk->info; const char *hookname = ETHER_DEFAULT_HOOK;