Wed Jan 29 04:34:10 2020 UTC ()
Adopt <net/if_stats.h>.


(thorpej)
diff -r1.25 -r1.26 src/sys/net/if_ipsec.c
diff -r1.157 -r1.158 src/sys/net/if_tun.c

cvs diff -r1.25 -r1.26 src/sys/net/if_ipsec.c (expand / switch to unified diff)

--- src/sys/net/if_ipsec.c 2019/11/01 04:28:14 1.25
+++ src/sys/net/if_ipsec.c 2020/01/29 04:34:10 1.26
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_ipsec.c,v 1.25 2019/11/01 04:28:14 knakahara Exp $ */ 1/* $NetBSD: if_ipsec.c,v 1.26 2020/01/29 04:34:10 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2017 Internet Initiative Japan Inc. 4 * Copyright (c) 2017 Internet Initiative Japan Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.25 2019/11/01 04:28:14 knakahara Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.26 2020/01/29 04:34:10 thorpej Exp $");
31 31
32#ifdef _KERNEL_OPT 32#ifdef _KERNEL_OPT
33#include "opt_inet.h" 33#include "opt_inet.h"
34#endif 34#endif
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/kernel.h> 38#include <sys/kernel.h>
39#include <sys/mbuf.h> 39#include <sys/mbuf.h>
40#include <sys/socket.h> 40#include <sys/socket.h>
41#include <sys/sockio.h> 41#include <sys/sockio.h>
42#include <sys/errno.h> 42#include <sys/errno.h>
43#include <sys/ioctl.h> 43#include <sys/ioctl.h>
@@ -528,27 +528,27 @@ if_ipsec_output(struct ifnet *ifp, struc @@ -528,27 +528,27 @@ if_ipsec_output(struct ifnet *ifp, struc
528 IF_DROP(&ifp->if_snd); 528 IF_DROP(&ifp->if_snd);
529 m_freem(m); 529 m_freem(m);
530 goto end; 530 goto end;
531 } 531 }
532#endif 532#endif
533 533
534 error = if_ipsec_out_direct(var, m, dst->sa_family); 534 error = if_ipsec_out_direct(var, m, dst->sa_family);
535 535
536end: 536end:
537 if_ipsec_putref_variant(var, &psref); 537 if_ipsec_putref_variant(var, &psref);
538 curlwp_bindx(bound); 538 curlwp_bindx(bound);
539noref_end: 539noref_end:
540 if (error) 540 if (error)
541 ifp->if_oerrors++; 541 if_statinc(ifp, if_oerrors);
542 542
543 return error; 543 return error;
544} 544}
545 545
546static inline int 546static inline int
547if_ipsec_out_direct(struct ipsec_variant *var, struct mbuf *m, int family) 547if_ipsec_out_direct(struct ipsec_variant *var, struct mbuf *m, int family)
548{ 548{
549 struct ifnet *ifp = &var->iv_softc->ipsec_if; 549 struct ifnet *ifp = &var->iv_softc->ipsec_if;
550 int error; 550 int error;
551 int len; 551 int len;
552 552
553 KASSERT(if_ipsec_heldref_variant(var)); 553 KASSERT(if_ipsec_heldref_variant(var));
554 KASSERT(var->iv_output != NULL); 554 KASSERT(var->iv_output != NULL);
@@ -556,28 +556,27 @@ if_ipsec_out_direct(struct ipsec_variant @@ -556,28 +556,27 @@ if_ipsec_out_direct(struct ipsec_variant
556 len = m->m_pkthdr.len; 556 len = m->m_pkthdr.len;
557 557
558 /* input DLT_NULL frame to BPF */ 558 /* input DLT_NULL frame to BPF */
559 bpf_mtap(ifp, m, BPF_D_OUT); 559 bpf_mtap(ifp, m, BPF_D_OUT);
560 560
561 /* grab and chop off inner af type */ 561 /* grab and chop off inner af type */
562 /* XXX need pullup? */ 562 /* XXX need pullup? */
563 m_adj(m, sizeof(int)); 563 m_adj(m, sizeof(int));
564 564
565 error = var->iv_output(var, family, m); 565 error = var->iv_output(var, family, m);
566 if (error) 566 if (error)
567 return error; 567 return error;
568 568
569 ifp->if_opackets++; 569 if_statadd2(ifp, if_opackets, 1, if_obytes, len);
570 ifp->if_obytes += len; 
571 570
572 return 0; 571 return 0;
573} 572}
574 573
575void 574void
576if_ipsec_input(struct mbuf *m, int af, struct ifnet *ifp) 575if_ipsec_input(struct mbuf *m, int af, struct ifnet *ifp)
577{ 576{
578 577
579 KASSERT(ifp != NULL); 578 KASSERT(ifp != NULL);
580 579
581 m_set_rcvif(m, ifp); 580 m_set_rcvif(m, ifp);
582 581
583 bpf_mtap_af(ifp, af, m, BPF_D_IN); 582 bpf_mtap_af(ifp, af, m, BPF_D_IN);
@@ -599,42 +598,41 @@ if_ipsec_in_enqueue(struct mbuf *m, int  @@ -599,42 +598,41 @@ if_ipsec_in_enqueue(struct mbuf *m, int
599 */ 598 */
600 switch (af) { 599 switch (af) {
601#ifdef INET 600#ifdef INET
602 case AF_INET: 601 case AF_INET:
603 pktq = ip_pktq; 602 pktq = ip_pktq;
604 break; 603 break;
605#endif 604#endif
606#ifdef INET6 605#ifdef INET6
607 case AF_INET6: 606 case AF_INET6:
608 pktq = ip6_pktq; 607 pktq = ip6_pktq;
609 break; 608 break;
610#endif 609#endif
611 default: 610 default:
612 ifp->if_ierrors++; 611 if_statinc(ifp, if_ierrors);
613 m_freem(m); 612 m_freem(m);
614 return; 613 return;
615 } 614 }
616 615
617#if 1 616#if 1
618 const u_int h = curcpu()->ci_index; 617 const u_int h = curcpu()->ci_index;
619#else 618#else
620 const uint32_t h = pktq_rps_hash(m); 619 const uint32_t h = pktq_rps_hash(m);
621#endif 620#endif
622 pktlen = m->m_pkthdr.len; 621 pktlen = m->m_pkthdr.len;
623 if (__predict_true(pktq_enqueue(pktq, m, h))) { 622 if (__predict_true(pktq_enqueue(pktq, m, h))) {
624 ifp->if_ibytes += pktlen; 623 if_statadd2(ifp, if_ibytes, pktlen, if_ipackets, 1);
625 ifp->if_ipackets++; 
626 } else { 624 } else {
627 ifp->if_iqdrops++; 625 if_statinc(ifp, if_iqdrops);
628 m_freem(m); 626 m_freem(m);
629 } 627 }
630 628
631 return; 629 return;
632} 630}
633 631
634static inline int 632static inline int
635if_ipsec_check_salen(struct sockaddr *addr) 633if_ipsec_check_salen(struct sockaddr *addr)
636{ 634{
637 635
638 switch (addr->sa_family) { 636 switch (addr->sa_family) {
639#ifdef INET 637#ifdef INET
640 case AF_INET: 638 case AF_INET:

cvs diff -r1.157 -r1.158 src/sys/net/if_tun.c (expand / switch to unified diff)

--- src/sys/net/if_tun.c 2019/12/13 14:13:55 1.157
+++ src/sys/net/if_tun.c 2020/01/29 04:34:10 1.158
@@ -1,35 +1,35 @@ @@ -1,35 +1,35 @@
1/* $NetBSD: if_tun.c,v 1.157 2019/12/13 14:13:55 maxv Exp $ */ 1/* $NetBSD: if_tun.c,v 1.158 2020/01/29 04:34:10 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk> 4 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>
5 * Nottingham University 1987. 5 * Nottingham University 1987.
6 * 6 *
7 * This source may be freely distributed, however I would be interested 7 * This source may be freely distributed, however I would be interested
8 * in any changes that are made. 8 * in any changes that are made.
9 * 9 *
10 * This driver takes packets off the IP i/f and hands them up to a 10 * This driver takes packets off the IP i/f and hands them up to a
11 * user process to have its wicked way with. This driver has its 11 * user process to have its wicked way with. This driver has its
12 * roots in a similar driver written by Phil Cockcroft (formerly) at 12 * roots in a similar driver written by Phil Cockcroft (formerly) at
13 * UCL. This driver is based much more on read/write/poll mode of 13 * UCL. This driver is based much more on read/write/poll mode of
14 * operation though. 14 * operation though.
15 */ 15 */
16 16
17/* 17/*
18 * tun - tunnel software network interface. 18 * tun - tunnel software network interface.
19 */ 19 */
20 20
21#include <sys/cdefs.h> 21#include <sys/cdefs.h>
22__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.157 2019/12/13 14:13:55 maxv Exp $"); 22__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.158 2020/01/29 04:34:10 thorpej Exp $");
23 23
24#ifdef _KERNEL_OPT 24#ifdef _KERNEL_OPT
25#include "opt_inet.h" 25#include "opt_inet.h"
26#endif 26#endif
27 27
28#include <sys/param.h> 28#include <sys/param.h>
29 29
30#include <sys/buf.h> 30#include <sys/buf.h>
31#include <sys/conf.h> 31#include <sys/conf.h>
32#include <sys/cpu.h> 32#include <sys/cpu.h>
33#include <sys/device.h> 33#include <sys/device.h>
34#include <sys/file.h> 34#include <sys/file.h>
35#include <sys/ioctl.h> 35#include <sys/ioctl.h>
@@ -249,33 +249,26 @@ tunattach0(struct tun_softc *tp) @@ -249,33 +249,26 @@ tunattach0(struct tun_softc *tp)
249 249
250 ifp = &tp->tun_if; 250 ifp = &tp->tun_if;
251 ifp->if_softc = tp; 251 ifp->if_softc = tp;
252 ifp->if_mtu = TUNMTU; 252 ifp->if_mtu = TUNMTU;
253 ifp->if_ioctl = tun_ioctl; 253 ifp->if_ioctl = tun_ioctl;
254 ifp->if_output = tun_output; 254 ifp->if_output = tun_output;
255#ifdef ALTQ 255#ifdef ALTQ
256 ifp->if_start = tunstart; 256 ifp->if_start = tunstart;
257#endif 257#endif
258 ifp->if_flags = IFF_POINTOPOINT; 258 ifp->if_flags = IFF_POINTOPOINT;
259 ifp->if_extflags = IFEF_NO_LINK_STATE_CHANGE; 259 ifp->if_extflags = IFEF_NO_LINK_STATE_CHANGE;
260 ifp->if_type = IFT_TUNNEL; 260 ifp->if_type = IFT_TUNNEL;
261 ifp->if_snd.ifq_maxlen = ifqmaxlen; 261 ifp->if_snd.ifq_maxlen = ifqmaxlen;
262 ifp->if_collisions = 0; 
263 ifp->if_ierrors = 0; 
264 ifp->if_oerrors = 0; 
265 ifp->if_ipackets = 0; 
266 ifp->if_opackets = 0; 
267 ifp->if_ibytes = 0; 
268 ifp->if_obytes = 0; 
269 ifp->if_dlt = DLT_NULL; 262 ifp->if_dlt = DLT_NULL;
270 IFQ_SET_READY(&ifp->if_snd); 263 IFQ_SET_READY(&ifp->if_snd);
271 if_attach(ifp); 264 if_attach(ifp);
272 if_alloc_sadl(ifp); 265 if_alloc_sadl(ifp);
273 bpf_attach(ifp, DLT_NULL, sizeof(uint32_t)); 266 bpf_attach(ifp, DLT_NULL, sizeof(uint32_t));
274} 267}
275 268
276static int 269static int
277tun_clone_destroy(struct ifnet *ifp) 270tun_clone_destroy(struct ifnet *ifp)
278{ 271{
279 struct tun_softc *tp = (void *)ifp; 272 struct tun_softc *tp = (void *)ifp;
280 bool zombie = false; 273 bool zombie = false;
281 274
@@ -602,33 +595,32 @@ tun_output(struct ifnet *ifp, struct mbu @@ -602,33 +595,32 @@ tun_output(struct ifnet *ifp, struct mbu
602#ifdef INET 595#ifdef INET
603 if (dst->sa_family != AF_INET) 596 if (dst->sa_family != AF_INET)
604#endif 597#endif
605 { 598 {
606 error = EAFNOSUPPORT; 599 error = EAFNOSUPPORT;
607 goto out; 600 goto out;
608 } 601 }
609 } 602 }
610 /* FALLTHROUGH */ 603 /* FALLTHROUGH */
611 case AF_UNSPEC: 604 case AF_UNSPEC:
612 mlen = m0->m_pkthdr.len; 605 mlen = m0->m_pkthdr.len;
613 IFQ_ENQUEUE(&ifp->if_snd, m0, error); 606 IFQ_ENQUEUE(&ifp->if_snd, m0, error);
614 if (error) { 607 if (error) {
615 ifp->if_collisions++; 608 if_statinc(ifp, if_collisions);
616 error = EAFNOSUPPORT; 609 error = EAFNOSUPPORT;
617 m0 = NULL; 610 m0 = NULL;
618 goto out; 611 goto out;
619 } 612 }
620 ifp->if_opackets++; 613 if_statadd2(ifp, if_opackets, 1, if_obytes, mlen);
621 ifp->if_obytes += mlen; 
622 break; 614 break;
623#endif 615#endif
624 default: 616 default:
625 error = EAFNOSUPPORT; 617 error = EAFNOSUPPORT;
626 goto out; 618 goto out;
627 } 619 }
628 620
629 mutex_enter(&tp->tun_lock); 621 mutex_enter(&tp->tun_lock);
630 if (tp->tun_flags & TUN_RWAIT) { 622 if (tp->tun_flags & TUN_RWAIT) {
631 tp->tun_flags &= ~TUN_RWAIT; 623 tp->tun_flags &= ~TUN_RWAIT;
632 cv_broadcast(&tp->tun_cv); 624 cv_broadcast(&tp->tun_cv);
633 } 625 }
634 if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid) 626 if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
@@ -818,27 +810,27 @@ tunread(dev_t dev, struct uio *uio, int  @@ -818,27 +810,27 @@ tunread(dev_t dev, struct uio *uio, int
818 /* Copy the mbuf chain */ 810 /* Copy the mbuf chain */
819 while (m0 && uio->uio_resid > 0 && error == 0) { 811 while (m0 && uio->uio_resid > 0 && error == 0) {
820 len = uimin(uio->uio_resid, m0->m_len); 812 len = uimin(uio->uio_resid, m0->m_len);
821 if (len != 0) 813 if (len != 0)
822 error = uiomove(mtod(m0, void *), len, uio); 814 error = uiomove(mtod(m0, void *), len, uio);
823 m0 = m = m_free(m0); 815 m0 = m = m_free(m0);
824 } 816 }
825 817
826 if (m0) { 818 if (m0) {
827 TUNDEBUG("Dropping mbuf\n"); 819 TUNDEBUG("Dropping mbuf\n");
828 m_freem(m0); 820 m_freem(m0);
829 } 821 }
830 if (error) 822 if (error)
831 ifp->if_ierrors++; 823 if_statinc(ifp, if_ierrors);
832 824
833 return error; 825 return error;
834 826
835out: 827out:
836 mutex_exit(&tp->tun_lock); 828 mutex_exit(&tp->tun_lock);
837 829
838 return error; 830 return error;
839} 831}
840 832
841/* 833/*
842 * the cdevsw write interface - an atomic write is a packet - or else! 834 * the cdevsw write interface - an atomic write is a packet - or else!
843 */ 835 */
844int 836int
@@ -936,55 +928,54 @@ tunwrite(dev_t dev, struct uio *uio, int @@ -936,55 +928,54 @@ tunwrite(dev_t dev, struct uio *uio, int
936 mp = &m->m_next; 928 mp = &m->m_next;
937 if (error == 0 && uio->uio_resid > 0) { 929 if (error == 0 && uio->uio_resid > 0) {
938 MGET(m, M_DONTWAIT, MT_DATA); 930 MGET(m, M_DONTWAIT, MT_DATA);
939 if (m == NULL) { 931 if (m == NULL) {
940 error = ENOBUFS; 932 error = ENOBUFS;
941 break; 933 break;
942 } 934 }
943 mlen = MLEN; 935 mlen = MLEN;
944 } 936 }
945 } 937 }
946 if (error) { 938 if (error) {
947 if (top != NULL) 939 if (top != NULL)
948 m_freem(top); 940 m_freem(top);
949 ifp->if_ierrors++; 941 if_statinc(ifp, if_ierrors);
950 goto out0; 942 goto out0;
951 } 943 }
952 944
953 top->m_pkthdr.len = tlen; 945 top->m_pkthdr.len = tlen;
954 m_set_rcvif(top, ifp); 946 m_set_rcvif(top, ifp);
955 947
956 bpf_mtap_af(ifp, dst.sa_family, top, BPF_D_IN); 948 bpf_mtap_af(ifp, dst.sa_family, top, BPF_D_IN);
957 949
958 if ((error = pfil_run_hooks(ifp->if_pfil, &top, ifp, PFIL_IN)) != 0) 950 if ((error = pfil_run_hooks(ifp->if_pfil, &top, ifp, PFIL_IN)) != 0)
959 goto out0; 951 goto out0;
960 if (top == NULL) 952 if (top == NULL)
961 goto out0; 953 goto out0;
962 954
963 mutex_enter(&tp->tun_lock); 955 mutex_enter(&tp->tun_lock);
964 if ((tp->tun_flags & TUN_INITED) == 0) { 956 if ((tp->tun_flags & TUN_INITED) == 0) {
965 /* Interface was destroyed */ 957 /* Interface was destroyed */
966 error = ENXIO; 958 error = ENXIO;
967 goto out; 959 goto out;
968 } 960 }
969 if (__predict_false(!pktq_enqueue(pktq, top, 0))) { 961 if (__predict_false(!pktq_enqueue(pktq, top, 0))) {
970 ifp->if_collisions++; 962 if_statinc(ifp, if_collisions);
971 mutex_exit(&tp->tun_lock); 963 mutex_exit(&tp->tun_lock);
972 error = ENOBUFS; 964 error = ENOBUFS;
973 m_freem(top); 965 m_freem(top);
974 goto out0; 966 goto out0;
975 } 967 }
976 ifp->if_ipackets++; 968 if_statadd2(ifp, if_ipackets, 1, if_ibytes, tlen);
977 ifp->if_ibytes += tlen; 
978out: 969out:
979 mutex_exit(&tp->tun_lock); 970 mutex_exit(&tp->tun_lock);
980out0: 971out0:
981 return error; 972 return error;
982} 973}
983 974
984#ifdef ALTQ 975#ifdef ALTQ
985/* 976/*
986 * Start packet transmission on the interface. 977 * Start packet transmission on the interface.
987 * when the interface queue is rate-limited by ALTQ or TBR, 978 * when the interface queue is rate-limited by ALTQ or TBR,
988 * if_start is needed to drain packets from the queue in order 979 * if_start is needed to drain packets from the queue in order
989 * to notify readers when outgoing packets become ready. 980 * to notify readers when outgoing packets become ready.
990 */ 981 */