summaryrefslogtreecommitdiffstats
path: root/sys/netinet/ip_input.c
diff options
context:
space:
mode:
authorbz <bz@FreeBSD.org>2010-09-02 17:43:44 +0000
committerbz <bz@FreeBSD.org>2010-09-02 17:43:44 +0000
commit18b40a43ee40b60f16950803b49724d0ef523293 (patch)
tree230de1f4337a85ebf5c0a3f05c9883bdd78fba3d /sys/netinet/ip_input.c
parentafcc72e27209509f7b650cea4f8607fb316ea2de (diff)
downloadFreeBSD-src-18b40a43ee40b60f16950803b49724d0ef523293.zip
FreeBSD-src-18b40a43ee40b60f16950803b49724d0ef523293.tar.gz
MFp4 CH=183052 183053 183258:
In protosw we define pr_protocol as short, while on the wire it is an uint8_t. That way we can have "internal" protocols like DIVERT, SEND or gaps for modules (PROTO_SPACER). Switch ipproto_{un,}register to accept a short protocol number(*) and do an upfront check for valid boundries. With this we also consistently report EPROTONOSUPPORT for out of bounds protocols, as we did for proto == 0. This allows a caller to not error for this case, which is especially important if we want to automatically call these from domain handling. (*) the functions have been without any in-tree consumer since the initial introducation, so this is considered save. Implement ip6proto_{un,}register() similarly to their legacy IP counter parts to allow modules to hook up dynamically. Reviewed by: philip, will MFC after: 1 week
Diffstat (limited to 'sys/netinet/ip_input.c')
-rw-r--r--sys/netinet/ip_input.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c
index 40b494a..6e1153d 100644
--- a/sys/netinet/ip_input.c
+++ b/sys/netinet/ip_input.c
@@ -1287,12 +1287,12 @@ ip_drain(void)
* in inetsw[], either statically or through pf_proto_register().
*/
int
-ipproto_register(u_char ipproto)
+ipproto_register(short ipproto)
{
struct protosw *pr;
/* Sanity checks. */
- if (ipproto == 0)
+ if (ipproto <= 0 || ipproto >= IPPROTO_MAX)
return (EPROTONOSUPPORT);
/*
@@ -1310,24 +1310,20 @@ ipproto_register(u_char ipproto)
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);
+ ip_protox[pr->pr_protocol] = pr - inetsw;
+ return (0);
}
}
return (EPROTONOSUPPORT);
}
int
-ipproto_unregister(u_char ipproto)
+ipproto_unregister(short ipproto)
{
struct protosw *pr;
/* Sanity checks. */
- if (ipproto == 0)
+ if (ipproto <= 0 || ipproto >= IPPROTO_MAX)
return (EPROTONOSUPPORT);
/* Check if the protocol was indeed registered. */
OpenPOWER on IntegriCloud