--- embedaddon/mpd/src/link.c 2013/07/22 08:44:29 1.1.1.1 +++ embedaddon/mpd/src/link.c 2019/10/22 13:49:55 1.1.1.3 @@ -145,6 +145,7 @@ { 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 }, }; @@ -428,6 +429,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); @@ -717,6 +719,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 +742,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); @@ -818,7 +834,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 +845,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 +867,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 +875,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); @@ -894,7 +910,7 @@ LinkNgDataEvent(int type, void *cookie) 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; } @@ -907,7 +923,7 @@ LinkNgDataEvent(int type, void *cookie) /* Debugging */ LogDumpBp(LG_FRAME, bp, - "[%s] rec'd %d bytes bypass frame link=%d proto=0x%04x", + "[%s] rec'd %zu bytes bypass frame link=%d proto=0x%04x", b->name, MBLEN(bp), (int16_t)linkNum, proto); /* Set link */ @@ -924,7 +940,7 @@ LinkNgDataEvent(int type, void *cookie) /* 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 */ @@ -1088,7 +1104,7 @@ AuthnameCommand(Context ctx, int ac, char *av[], void { int k; - if (ac > 1) + if (ac > 2) return (-1); if (ac == 0) { @@ -1100,11 +1116,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); @@ -1335,9 +1359,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