diff options
| author | Andre Oppermann <andre@FreeBSD.org> | 2004-10-19 15:45:57 +0000 |
|---|---|---|
| committer | Andre Oppermann <andre@FreeBSD.org> | 2004-10-19 15:45:57 +0000 |
| commit | de38924dc085e249ce2942c8d5a339daba5956e9 (patch) | |
| tree | 5e1381e3fd7b17aca48188a8e5c4717260ca205f /sys/netinet/ip_input.c | |
| parent | 33bab57d1ecff2cad8f392b69924f6d163d3eb61 (diff) | |
Notes
Diffstat (limited to 'sys/netinet/ip_input.c')
| -rw-r--r-- | sys/netinet/ip_input.c | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 37fbfd67199c6..b950504b16f06 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -261,7 +261,7 @@ ip_init() if (pr->pr_domain->dom_family == PF_INET && pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) { /* Be careful to only index valid IP protocols. */ - if (pr->pr_protocol && pr->pr_protocol < IPPROTO_MAX) + if (pr->pr_protocol <= IPPROTO_MAX) ip_protox[pr->pr_protocol] = pr - inetsw; } @@ -1145,6 +1145,67 @@ ip_drain() } /* + * The protocol to be inserted into ip_protox[] must be already registered + * in inetsw[], either statically or through pf_proto_register(). + */ +int +ipproto_register(u_char ipproto) +{ + struct protosw *pr; + + /* Sanity checks. */ + if (ipproto == 0) + return (EPROTONOSUPPORT); + + /* + * The protocol slot must not be occupied by another protocol + * already. An index pointing to IPPROTO_RAW is unused. + */ + pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW); + if (pr == NULL) + return (EPFNOSUPPORT); + if (ip_protox[ipproto] != pr - inetsw) /* IPPROTO_RAW */ + return (EEXIST); + + /* Find the protocol position in inetsw[] and set the index. */ + for (pr = inetdomain.dom_protosw; + pr < inetdomain.dom_protoswNPROTOSW; pr++) { + if (pr->pr_domain->dom_family == PF_INET && + pr->pr_protocol && pr->pr_protocol == ipproto) { + /* Be careful to only index valid IP protocols. */ + if (pr->pr_protocol <= IPPROTO_MAX) { + ip_protox[pr->pr_protocol] = pr - inetsw; + return (0); + } else + return (EINVAL); + } + } + return (EPROTONOSUPPORT); +} + +int +ipproto_unregister(u_char ipproto) +{ + struct protosw *pr; + + /* Sanity checks. */ + if (ipproto == 0) + return (EPROTONOSUPPORT); + + /* Check if the protocol was indeed registered. */ + pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW); + if (pr == NULL) + return (EPFNOSUPPORT); + if (ip_protox[ipproto] == pr - inetsw) /* IPPROTO_RAW */ + return (ENOENT); + + /* Reset the protocol slot to IPPROTO_RAW. */ + ip_protox[ipproto] = pr - inetsw; + return (0); +} + + +/* * Do option processing on a datagram, * possibly discarding it if bad options are encountered, * or forwarding it if source-routed. |
