MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ng_ppp_newhook

Function ng_ppp_newhook

freebsd/netgraph/ng_ppp.c:519–577  ·  view source on GitHub ↗

* Give our OK for a hook to be added */

Source from the content-addressed store, hash-verified

517 * Give our OK for a hook to be added
518 */
519static int
520ng_ppp_newhook(node_p node, hook_p hook, const char *name)
521{
522 const priv_p priv = NG_NODE_PRIVATE(node);
523 hook_p *hookPtr = NULL;
524 int linkNum = -1;
525 int hookIndex = -1;
526
527 /* Figure out which hook it is */
528 if (strncmp(name, NG_PPP_HOOK_LINK_PREFIX, /* a link hook? */
529 strlen(NG_PPP_HOOK_LINK_PREFIX)) == 0) {
530 const char *cp;
531 char *eptr;
532
533 cp = name + strlen(NG_PPP_HOOK_LINK_PREFIX);
534 if (!isdigit(*cp) || (cp[0] == '0' && cp[1] != '\0'))
535 return (EINVAL);
536 linkNum = (int)strtoul(cp, &eptr, 10);
537 if (*eptr != '\0' || linkNum < 0 || linkNum >= NG_PPP_MAX_LINKS)
538 return (EINVAL);
539 hookPtr = &priv->links[linkNum].hook;
540 hookIndex = ~linkNum;
541
542 /* See if hook is already connected. */
543 if (*hookPtr != NULL)
544 return (EISCONN);
545
546 /* Disallow more than one link unless multilink is enabled. */
547 if (priv->links[linkNum].conf.enableLink &&
548 !priv->conf.enableMultilink && priv->numActiveLinks >= 1)
549 return (ENODEV);
550
551 } else { /* must be a non-link hook */
552 int i;
553
554 for (i = 0; ng_ppp_hook_names[i].name != NULL; i++) {
555 if (strcmp(name, ng_ppp_hook_names[i].name) == 0) {
556 hookPtr = &priv->hooks[i];
557 hookIndex = i;
558 break;
559 }
560 }
561 if (ng_ppp_hook_names[i].name == NULL)
562 return (EINVAL); /* no such hook */
563
564 /* See if hook is already connected */
565 if (*hookPtr != NULL)
566 return (EISCONN);
567
568 /* Every non-linkX hook have it's own function. */
569 NG_HOOK_SET_RCVDATA(hook, ng_ppp_hook_names[i].fn);
570 }
571
572 /* OK */
573 *hookPtr = hook;
574 NG_HOOK_SET_PRIVATE(hook, (void *)(intptr_t)hookIndex);
575 ng_ppp_update(node, 0);
576 return (0);

Callers

nothing calls this directly

Calls 5

strncmpFunction · 0.85
isdigitFunction · 0.85
strtoulFunction · 0.85
strcmpFunction · 0.85
ng_ppp_updateFunction · 0.85

Tested by

no test coverage detected