diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2019-04-19 07:38:03 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2019-04-19 07:38:03 +0000 |
commit | ff5b339875e7f79bf5360040db863efaa26bac4c (patch) | |
tree | 9daea2b49872193919dfb9a8cd17b9b17b492f32 /sys | |
parent | 4a139c89513bc7fb60152589c64b28b0d15bfb7d (diff) |
provide factored out txhprio and rxhprio checks
l2 and l3 drivers do the same thing all the time, so reduce the
chance of error by doing the checks once and making it available
for drivers to call instead of rolling on their own again.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/if.c | 66 | ||||
-rw-r--r-- | sys/net/if_var.h | 7 |
2 files changed, 71 insertions, 2 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index 473c9d2a1bf..88b79a6cdda 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.577 2019/04/19 04:22:09 dlg Exp $ */ +/* $OpenBSD: if.c,v 1.578 2019/04/19 07:38:02 dlg Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -2335,6 +2335,70 @@ if_sffpage_check(const caddr_t data) return (0); } +int +if_txhprio_l2_check(int hdrprio) +{ + switch (hdrprio) { + case IF_HDRPRIO_PACKET: + return (0); + default: + if (hdrprio >= IF_HDRPRIO_MIN && hdrprio <= IF_HDRPRIO_MAX) + return (0); + break; + } + + return (EINVAL); +} + +int +if_txhprio_l3_check(int hdrprio) +{ + switch (hdrprio) { + case IF_HDRPRIO_PACKET: + case IF_HDRPRIO_PAYLOAD: + return (0); + default: + if (hdrprio >= IF_HDRPRIO_MIN && hdrprio <= IF_HDRPRIO_MAX) + return (0); + break; + } + + return (EINVAL); +} + +int +if_rxhprio_l2_check(int hdrprio) +{ + switch (hdrprio) { + case IF_HDRPRIO_PACKET: + case IF_HDRPRIO_OUTER: + return (0); + default: + if (hdrprio >= IF_HDRPRIO_MIN && hdrprio <= IF_HDRPRIO_MAX) + return (0); + break; + } + + return (EINVAL); +} + +int +if_rxhprio_l3_check(int hdrprio) +{ + switch (hdrprio) { + case IF_HDRPRIO_PACKET: + case IF_HDRPRIO_PAYLOAD: + case IF_HDRPRIO_OUTER: + return (0); + default: + if (hdrprio >= IF_HDRPRIO_MIN && hdrprio <= IF_HDRPRIO_MAX) + return (0); + break; + } + + return (EINVAL); +} + /* * Return interface configuration * of system. List may be used diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 634c6dff9e6..9547f66462f 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_var.h,v 1.96 2019/04/16 04:04:19 dlg Exp $ */ +/* $OpenBSD: if_var.h,v 1.97 2019/04/19 07:38:02 dlg Exp $ */ /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ /* @@ -387,6 +387,11 @@ int if_rxr_ioctl(struct if_rxrinfo *, const char *, u_int, void if_counters_alloc(struct ifnet *); void if_counters_free(struct ifnet *); +int if_txhprio_l2_check(int); +int if_txhprio_l3_check(int); +int if_rxhprio_l2_check(int); +int if_rxhprio_l3_check(int); + #endif /* _KERNEL */ #endif /* _NET_IF_VAR_H_ */ |