| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: if_pfsync.c,v 1.19 2018/12/22 14:28:56 maxv Exp $ */ | | 1 | /* $NetBSD: if_pfsync.c,v 1.20 2020/01/29 05:52:27 thorpej Exp $ */ |
2 | /* $OpenBSD: if_pfsync.c,v 1.83 2007/06/26 14:44:12 mcbride Exp $ */ | | 2 | /* $OpenBSD: if_pfsync.c,v 1.83 2007/06/26 14:44:12 mcbride Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright (c) 2002 Michael Shalayeff | | 5 | * Copyright (c) 2002 Michael Shalayeff |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -18,27 +18,27 @@ | | | @@ -18,27 +18,27 @@ |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, | | 20 | * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, |
21 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | 21 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | | 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
23 | * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 23 | * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | | 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | | 25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
27 | * THE POSSIBILITY OF SUCH DAMAGE. | | 27 | * THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ | | 28 | */ |
29 | | | 29 | |
30 | #include <sys/cdefs.h> | | 30 | #include <sys/cdefs.h> |
31 | __KERNEL_RCSID(0, "$NetBSD: if_pfsync.c,v 1.19 2018/12/22 14:28:56 maxv Exp $"); | | 31 | __KERNEL_RCSID(0, "$NetBSD: if_pfsync.c,v 1.20 2020/01/29 05:52:27 thorpej Exp $"); |
32 | | | 32 | |
33 | #ifdef _KERNEL_OPT | | 33 | #ifdef _KERNEL_OPT |
34 | #include "opt_inet.h" | | 34 | #include "opt_inet.h" |
35 | #include "opt_inet6.h" | | 35 | #include "opt_inet6.h" |
36 | #endif | | 36 | #endif |
37 | | | 37 | |
38 | #include <sys/param.h> | | 38 | #include <sys/param.h> |
39 | #include <sys/proc.h> | | 39 | #include <sys/proc.h> |
40 | #include <sys/systm.h> | | 40 | #include <sys/systm.h> |
41 | #include <sys/time.h> | | 41 | #include <sys/time.h> |
42 | #include <sys/mbuf.h> | | 42 | #include <sys/mbuf.h> |
43 | #include <sys/socket.h> | | 43 | #include <sys/socket.h> |
44 | #include <sys/ioctl.h> | | 44 | #include <sys/ioctl.h> |
| @@ -1035,27 +1035,31 @@ pfsync_setmtu(struct pfsync_softc *sc, i | | | @@ -1035,27 +1035,31 @@ pfsync_setmtu(struct pfsync_softc *sc, i |
1035 | sc->sc_if.if_mtu = sizeof(struct pfsync_header) + | | 1035 | sc->sc_if.if_mtu = sizeof(struct pfsync_header) + |
1036 | sc->sc_maxcount * sizeof(struct pfsync_state); | | 1036 | sc->sc_maxcount * sizeof(struct pfsync_state); |
1037 | } | | 1037 | } |
1038 | | | 1038 | |
1039 | struct mbuf * | | 1039 | struct mbuf * |
1040 | pfsync_get_mbuf(struct pfsync_softc *sc, u_int8_t action, void **sp) | | 1040 | pfsync_get_mbuf(struct pfsync_softc *sc, u_int8_t action, void **sp) |
1041 | { | | 1041 | { |
1042 | struct pfsync_header *h; | | 1042 | struct pfsync_header *h; |
1043 | struct mbuf *m; | | 1043 | struct mbuf *m; |
1044 | int len; | | 1044 | int len; |
1045 | | | 1045 | |
1046 | MGETHDR(m, M_DONTWAIT, MT_DATA); | | 1046 | MGETHDR(m, M_DONTWAIT, MT_DATA); |
1047 | if (m == NULL) { | | 1047 | if (m == NULL) { |
| | | 1048 | #ifdef __NetBSD__ |
| | | 1049 | if_statinc(&sc->sc_if, if_oerrors); |
| | | 1050 | #else |
1048 | sc->sc_if.if_oerrors++; | | 1051 | sc->sc_if.if_oerrors++; |
| | | 1052 | #endif /* __NetBSD__ */ |
1049 | return (NULL); | | 1053 | return (NULL); |
1050 | } | | 1054 | } |
1051 | | | 1055 | |
1052 | switch (action) { | | 1056 | switch (action) { |
1053 | case PFSYNC_ACT_CLR: | | 1057 | case PFSYNC_ACT_CLR: |
1054 | len = sizeof(struct pfsync_header) + | | 1058 | len = sizeof(struct pfsync_header) + |
1055 | sizeof(struct pfsync_state_clr); | | 1059 | sizeof(struct pfsync_state_clr); |
1056 | break; | | 1060 | break; |
1057 | case PFSYNC_ACT_UPD_C: | | 1061 | case PFSYNC_ACT_UPD_C: |
1058 | len = (sc->sc_maxcount * sizeof(struct pfsync_state_upd)) + | | 1062 | len = (sc->sc_maxcount * sizeof(struct pfsync_state_upd)) + |
1059 | sizeof(struct pfsync_header); | | 1063 | sizeof(struct pfsync_header); |
1060 | break; | | 1064 | break; |
1061 | case PFSYNC_ACT_DEL_C: | | 1065 | case PFSYNC_ACT_DEL_C: |
| @@ -1074,27 +1078,31 @@ pfsync_get_mbuf(struct pfsync_softc *sc, | | | @@ -1074,27 +1078,31 @@ pfsync_get_mbuf(struct pfsync_softc *sc, |
1074 | len = (sc->sc_maxcount * sizeof(struct pfsync_tdb)) + | | 1078 | len = (sc->sc_maxcount * sizeof(struct pfsync_tdb)) + |
1075 | sizeof(struct pfsync_header); | | 1079 | sizeof(struct pfsync_header); |
1076 | break; | | 1080 | break; |
1077 | default: | | 1081 | default: |
1078 | len = (sc->sc_maxcount * sizeof(struct pfsync_state)) + | | 1082 | len = (sc->sc_maxcount * sizeof(struct pfsync_state)) + |
1079 | sizeof(struct pfsync_header); | | 1083 | sizeof(struct pfsync_header); |
1080 | break; | | 1084 | break; |
1081 | } | | 1085 | } |
1082 | | | 1086 | |
1083 | if (len > MHLEN) { | | 1087 | if (len > MHLEN) { |
1084 | MCLGET(m, M_DONTWAIT); | | 1088 | MCLGET(m, M_DONTWAIT); |
1085 | if ((m->m_flags & M_EXT) == 0) { | | 1089 | if ((m->m_flags & M_EXT) == 0) { |
1086 | m_free(m); | | 1090 | m_free(m); |
| | | 1091 | #ifdef __NetBSD__ |
| | | 1092 | if_statinc(&sc->sc_if, if_oerrors); |
| | | 1093 | #else |
1087 | sc->sc_if.if_oerrors++; | | 1094 | sc->sc_if.if_oerrors++; |
| | | 1095 | #endif /* __NetBSD__ */ |
1088 | return (NULL); | | 1096 | return (NULL); |
1089 | } | | 1097 | } |
1090 | m->m_data += (MCLBYTES - len) &~ (sizeof(long) - 1); | | 1098 | m->m_data += (MCLBYTES - len) &~ (sizeof(long) - 1); |
1091 | } else | | 1099 | } else |
1092 | m_align(m, len); | | 1100 | m_align(m, len); |
1093 | | | 1101 | |
1094 | m_reset_rcvif(m); | | 1102 | m_reset_rcvif(m); |
1095 | m->m_pkthdr.len = m->m_len = sizeof(struct pfsync_header); | | 1103 | m->m_pkthdr.len = m->m_len = sizeof(struct pfsync_header); |
1096 | h = mtod(m, struct pfsync_header *); | | 1104 | h = mtod(m, struct pfsync_header *); |
1097 | h->version = PFSYNC_VERSION; | | 1105 | h->version = PFSYNC_VERSION; |
1098 | h->af = 0; | | 1106 | h->af = 0; |
1099 | h->count = 0; | | 1107 | h->count = 0; |
1100 | h->action = action; | | 1108 | h->action = action; |