--- embedaddon/mpd/src/link.c 2012/02/21 23:32:47 1.1 +++ embedaddon/mpd/src/link.c 2021/03/17 00:39:23 1.1.1.4 @@ -58,7 +58,7 @@ * INTERNAL FUNCTIONS */ - static int LinkSetCommand(Context ctx, int ac, char *av[], void *arg); + static int LinkSetCommand(Context ctx, int ac, const char *const av[], const void *arg); static void LinkMsg(int type, void *cookie); static void LinkNgDataEvent(int type, void *cookie); static void LinkReopenTimeout(void *arg); @@ -67,7 +67,7 @@ * GLOBAL VARIABLES */ - const struct cmdtab LinkSetActionCmds[] = { + static const struct cmdtab LinkSetActionCmds[] = { { "bundle {bundle} [{regex}]", "Terminate incomings locally", LinkSetCommand, NULL, 2, (void *) SET_BUNDLE }, { "forward {link} [{regex}]", "Forward incomings", @@ -76,12 +76,12 @@ LinkSetCommand, NULL, 2, (void *) SET_DROP }, { "clear", "Clear actions", LinkSetCommand, NULL, 2, (void *) SET_CLEAR }, - { NULL }, + { NULL, NULL, NULL, NULL, 0, NULL }, }; const struct cmdtab LinkSetCmds[] = { { "action ...", "Set action on incoming", - CMD_SUBMENU, NULL, 2, (void *) LinkSetActionCmds }, + CMD_SUBMENU, NULL, 2, LinkSetActionCmds }, { "bandwidth {bps}", "Link bandwidth", LinkSetCommand, NULL, 2, (void *) SET_BANDWIDTH }, { "latency {microsecs}", "Link latency", @@ -118,14 +118,14 @@ LinkSetCommand, NULL, 2, (void *) SET_YES }, { "no {opt ...}", "Disable and deny option", LinkSetCommand, NULL, 2, (void *) SET_NO }, - { NULL }, + { NULL, NULL, NULL, NULL, 0, NULL }, }; /* * INTERNAL VARIABLES */ - static struct confinfo gConfList[] = { + static const struct confinfo gConfList[] = { { 0, LINK_CONF_INCOMING, "incoming" }, { 1, LINK_CONF_PAP, "pap" }, { 1, LINK_CONF_CHAPMD5, "chap-md5" }, @@ -145,12 +145,13 @@ { 0, LINK_CONF_TIMEREMAIN, "time-remain" }, { 0, LINK_CONF_PEER_AS_CALLING, "peer-as-calling" }, { 0, LINK_CONF_REPORT_MAC, "report-mac" }, + { 0, LINK_CONF_REMOVE_TEE, "remove-tee" }, { 0, 0, NULL }, }; int gLinksCsock = -1; /* Socket node control socket */ int gLinksDsock = -1; /* Socket node data socket */ - EventRef gLinksDataEvent; + static EventRef gLinksDataEvent; int LinksInit(void) @@ -261,7 +262,7 @@ LinkDown(Link l) if (((l->conf.max_redial != 0) && (l->num_redial >= l->conf.max_redial)) || gShutdownInProgress) { if (l->conf.max_redial >= 0) { - Log(LG_LINK, ("[%s] Link: giving up after %d reconnection attempts", + Log(LG_LINK, ("[%s] Link: giving up after %hu reconnection attempts", l->name, l->num_redial)); } if (!l->stay) @@ -279,7 +280,7 @@ LinkDown(Link l) LcpDown(l); l->num_redial++; - Log(LG_LINK, ("[%s] Link: reconnection attempt %d in %d seconds", + Log(LG_LINK, ("[%s] Link: reconnection attempt %hu in %d seconds", l->name, l->num_redial, delay)); } } else { @@ -303,7 +304,7 @@ LinkReopenTimeout(void *arg) return; } - Log(LG_LINK, ("[%s] Link: reconnection attempt %d", + Log(LG_LINK, ("[%s] Link: reconnection attempt %hu", l->name, l->num_redial)); RecordLinkUpDownReason(NULL, l, 1, STR_REDIAL, NULL); PhysOpen(l); @@ -348,14 +349,15 @@ LinkMsg(int type, void *arg) */ int -LinkCreate(Context ctx, int ac, char *av[], void *arg) +LinkCreate(Context ctx, int ac, const char *const av[], const void *arg) { Link l, lt = NULL; - PhysType pt = NULL; + const struct phystype *pt = NULL; u_char tmpl = 0; u_char stay = 0; int k; + (void)arg; RESETREF(ctx->lnk, NULL); RESETREF(ctx->bund, NULL); RESETREF(ctx->rep, NULL); @@ -428,6 +430,7 @@ LinkCreate(Context ctx, int ac, char *av[], void *arg) l->upReasonValid = 0; l->downReason = NULL; l->downReasonValid = 0; + l->tee_removed = 0; Disable(&l->conf.options, LINK_CONF_CHAPMD5); Accept(&l->conf.options, LINK_CONF_CHAPMD5); @@ -485,10 +488,11 @@ LinkCreate(Context ctx, int ac, char *av[], void *arg) */ int -LinkDestroy(Context ctx, int ac, char *av[], void *arg) +LinkDestroy(Context ctx, int ac, const char *const av[], const void *arg) { Link l; + (void)arg; if (ac > 1) return(-1); @@ -526,7 +530,7 @@ LinkDestroy(Context ctx, int ac, char *av[], void *arg */ Link -LinkInst(Link lt, char *name, int tmpl, int stay) +LinkInst(Link lt, const char *name, int tmpl, int stay) { Link l; int k; @@ -717,6 +721,16 @@ LinkNgJoin(Link l) } NgFuncDisconnect(gLinksCsock, l->name, path, NG_TEE_HOOK_LEFT2RIGHT); + + if (Enabled(&l->conf.options, LINK_CONF_REMOVE_TEE)) { + if (l->stay == 0) { + Log(LG_LINK, ("[%s] Link: Removing ng_tee node", l->name)); + NgFuncShutdownNode(gLinksCsock, NG_TEE_NODE_TYPE, path); + l->tee_removed = 1; + } else + Log(LG_LINK, ("[%s] Link: Can't remove ng_tee node on static link", + l->name)); + } return (0); } @@ -730,6 +744,10 @@ LinkNgLeave(Link l) char path[NG_PATHSIZ]; struct ngm_connect cn; + /* ng_tee is already removed */ + if (l->tee_removed == 1) + return(0); + memset(&cn, 0, sizeof(cn)); snprintf(cn.path, sizeof(cn.path), "[%lx]:", (u_long)l->nodeID); strcpy(cn.ourhook, l->hook); @@ -799,13 +817,16 @@ LinkNgDataEvent(int type, void *cookie) Bund b; u_char *buf; u_int16_t proto; - int ptr; + unsigned ptr; Mbuf bp; struct sockaddr_ng naddr; socklen_t nsize; char *name, *rest; int id, num = 0; + (void)cookie; + (void)type; + /* Read all available packets */ while (1) { if (num > 20) @@ -818,7 +839,7 @@ LinkNgDataEvent(int type, void *cookie) mbfree(bp); if (errno == EAGAIN) return; - Log(LG_LINK, ("Link socket read error: %s", strerror(errno))); + Perror("Link: Link socket read error"); return; } num++; @@ -829,7 +850,7 @@ LinkNgDataEvent(int type, void *cookie) name++; id = strtol(name, &rest, 10); if (rest[0] != 0 || !gLinks[id]) { - Log(LG_ERR, ("Link: packet from unexisting link \"%s\"", + Log(LG_ERR, ("Link: Packet from unexisting link \"%s\"", name)); mbfree(bp); continue; @@ -851,7 +872,7 @@ LinkNgDataEvent(int type, void *cookie) if (MBLEN(bp) <= ptr) { LogDumpBp(LG_FRAME|LG_ERR, bp, - "[%s] rec'd truncated %d bytes frame from link", + "[%s] rec'd truncated %zu bytes frame from link", l->name, MBLEN(bp)); mbfree(bp); continue; @@ -859,7 +880,7 @@ LinkNgDataEvent(int type, void *cookie) /* Debugging */ LogDumpBp(LG_FRAME, bp, - "[%s] rec'd %d bytes frame from link proto=0x%04x", + "[%s] rec'd %zu bytes frame from link proto=0x%04x", l->name, MBLEN(bp), proto); bp = mbadj(bp, ptr); @@ -889,12 +910,12 @@ LinkNgDataEvent(int type, void *cookie) /* A PPP frame from the bypass hook? */ if (naddr.sg_data[0] == 'b') { - Link l; - u_int16_t linkNum, proto; + Link ll; + u_int16_t linkNum, lproto; if (MBLEN(bp) <= 4) { LogDumpBp(LG_FRAME|LG_ERR, bp, - "[%s] rec'd truncated %d bytes frame", + "[%s] rec'd truncated %zu bytes frame", b->name, MBLEN(bp)); continue; } @@ -902,29 +923,29 @@ LinkNgDataEvent(int type, void *cookie) /* Extract link number and protocol */ bp = mbread(bp, &linkNum, 2); linkNum = ntohs(linkNum); - bp = mbread(bp, &proto, 2); - proto = ntohs(proto); + bp = mbread(bp, &lproto, 2); + lproto = ntohs(lproto); /* Debugging */ LogDumpBp(LG_FRAME, bp, - "[%s] rec'd %d bytes bypass frame link=%d proto=0x%04x", - b->name, MBLEN(bp), (int16_t)linkNum, proto); + "[%s] rec'd %zu bytes bypass frame link=%d proto=0x%04x", + b->name, MBLEN(bp), (int16_t)linkNum, lproto); /* Set link */ assert(linkNum == NG_PPP_BUNDLE_LINKNUM || linkNum < NG_PPP_MAX_LINKS); if (linkNum != NG_PPP_BUNDLE_LINKNUM) - l = b->links[linkNum]; + ll = b->links[linkNum]; else - l = NULL; + ll = NULL; - InputFrame(b, l, proto, bp); + InputFrame(b, ll, lproto, bp); continue; } /* Debugging */ LogDumpBp(LG_FRAME, bp, - "[%s] rec'd %d bytes frame on %s hook", b->name, MBLEN(bp), naddr.sg_data); + "[%s] rec'd %zu bytes frame on %s hook", b->name, MBLEN(bp), naddr.sg_data); #ifndef USE_NG_TCPMSS /* A snooped, outgoing TCP SYN frame */ @@ -996,11 +1017,12 @@ LinkFind(const char *name) */ int -LinkCommand(Context ctx, int ac, char *av[], void *arg) +LinkCommand(Context ctx, int ac, const char *const av[], const void *arg) { Link l; int k; + (void)arg; if (ac > 1) return (-1); @@ -1042,10 +1064,11 @@ LinkCommand(Context ctx, int ac, char *av[], void *arg */ int -SessionCommand(Context ctx, int ac, char *av[], void *arg) +SessionCommand(Context ctx, int ac, const char *const av[], const void *arg) { int k; + (void)arg; if (ac > 1) return (-1); @@ -1084,11 +1107,12 @@ SessionCommand(Context ctx, int ac, char *av[], void * */ int -AuthnameCommand(Context ctx, int ac, char *av[], void *arg) +AuthnameCommand(Context ctx, int ac, const char *const av[], const void *arg) { int k; - if (ac > 1) + (void)arg; + if (ac > 2) return (-1); if (ac == 0) { @@ -1100,11 +1124,19 @@ AuthnameCommand(Context ctx, int ac, char *av[], void return (0); } - /* Find link */ - for (k = 0; - k < gNumLinks && (gLinks[k] == NULL || - strcmp(gLinks[k]->lcp.auth.params.authname, av[0])); - k++); + if (ac == 2 && strcasecmp(av[1], "ci") == 0) { + /* Find link */ + for (k = 0; + k < gNumLinks && (gLinks[k] == NULL || + strcasecmp(gLinks[k]->lcp.auth.params.authname, av[0])); + k++); + } else { + /* Find link */ + for (k = 0; + k < gNumLinks && (gLinks[k] == NULL || + strcmp(gLinks[k]->lcp.auth.params.authname, av[0])); + k++); + } if (k == gNumLinks) { /* Change default link and bundle */ RESETREF(ctx->lnk, NULL); @@ -1238,11 +1270,15 @@ LinkMatchAction(Link l, int stage, char *login) */ int -LinkStat(Context ctx, int ac, char *av[], void *arg) +LinkStat(Context ctx, int ac, const char *const av[], const void *arg) { Link l = ctx->lnk; struct linkaction *a; + (void)ac; + (void)av; + (void)arg; + Printf("Link %s%s:\r\n", l->name, l->tmpl?" (template)":(l->stay?" (static)":"")); Printf("Configuration:\r\n"); @@ -1335,9 +1371,9 @@ LinkUpdateStats(Link l) l->stats.runts += abs(stats.runts - l->oldStats.runts); l->stats.dupFragments += abs(stats.dupFragments - l->oldStats.dupFragments); l->stats.dropFragments += abs(stats.dropFragments - l->oldStats.dropFragments); + l->oldStats = stats; } - l->oldStats = stats; #else NgFuncGetStats64(l->bund, l->bundleIndex, &l->stats); #endif @@ -1363,12 +1399,12 @@ LinkResetStats(Link l) */ static int -LinkSetCommand(Context ctx, int ac, char *av[], void *arg) +LinkSetCommand(Context ctx, int ac, const char *const av[], const void *arg) { Link l = ctx->lnk; int val, nac = 0; const char *name; - char *nav[ac]; + const char *nav[ac]; const char *av2[] = { "chap-md5", "chap-msv1", "chap-msv2" }; /* make "chap" as an alias for all chap-variants, this should keep BC */ @@ -1383,7 +1419,7 @@ LinkSetCommand(Context ctx, int ac, char *av[], void * int i = 0; for ( ; i < ac; i++) { if (strcasecmp(av[i], "chap") == 0) { - LinkSetCommand(ctx, 3, (char **)av2, arg); + LinkSetCommand(ctx, 3, (const char **)av2, arg); } else { nav[nac++] = av[i]; }