Wed Jul 14 06:23:06 2021 UTC ()
Make an mbuf writable before un-tagging


(yamaguchi)
diff -r1.157 -r1.158 src/sys/net/if_vlan.c

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

--- src/sys/net/if_vlan.c 2021/07/06 02:39:46 1.157
+++ src/sys/net/if_vlan.c 2021/07/14 06:23:06 1.158
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_vlan.c,v 1.157 2021/07/06 02:39:46 yamaguchi Exp $ */ 1/* $NetBSD: if_vlan.c,v 1.158 2021/07/14 06:23:06 yamaguchi Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran, and by Jason R. Thorpe of Zembu Labs, Inc. 8 * by Andrew Doran, and by Jason R. Thorpe of Zembu Labs, Inc.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -68,27 +68,27 @@ @@ -68,27 +68,27 @@
68 * enough of an Ethernet implementation to make ARP work. The way we do 68 * enough of an Ethernet implementation to make ARP work. The way we do
69 * this is by telling everyone that we are an Ethernet interface, and then 69 * this is by telling everyone that we are an Ethernet interface, and then
70 * catch the packets that ether_output() left on our output queue when it 70 * catch the packets that ether_output() left on our output queue when it
71 * calls if_start(), rewrite them for use by the real outgoing interface, 71 * calls if_start(), rewrite them for use by the real outgoing interface,
72 * and ask it to send them. 72 * and ask it to send them.
73 * 73 *
74 * TODO: 74 * TODO:
75 * 75 *
76 * - Need some way to notify vlan interfaces when the parent 76 * - Need some way to notify vlan interfaces when the parent
77 * interface changes MTU. 77 * interface changes MTU.
78 */ 78 */
79 79
80#include <sys/cdefs.h> 80#include <sys/cdefs.h>
81__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.157 2021/07/06 02:39:46 yamaguchi Exp $"); 81__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.158 2021/07/14 06:23:06 yamaguchi Exp $");
82 82
83#ifdef _KERNEL_OPT 83#ifdef _KERNEL_OPT
84#include "opt_inet.h" 84#include "opt_inet.h"
85#include "opt_net_mpsafe.h" 85#include "opt_net_mpsafe.h"
86#endif 86#endif
87 87
88#include <sys/param.h> 88#include <sys/param.h>
89#include <sys/systm.h> 89#include <sys/systm.h>
90#include <sys/kernel.h> 90#include <sys/kernel.h>
91#include <sys/mbuf.h> 91#include <sys/mbuf.h>
92#include <sys/queue.h> 92#include <sys/queue.h>
93#include <sys/socket.h> 93#include <sys/socket.h>
94#include <sys/sockio.h> 94#include <sys/sockio.h>
@@ -1612,26 +1612,34 @@ vlan_input(struct ifnet *ifp, struct mbu @@ -1612,26 +1612,34 @@ vlan_input(struct ifnet *ifp, struct mbu
1612 struct ether_vlan_header *evl; 1612 struct ether_vlan_header *evl;
1613 1613
1614 if (ifp->if_type != IFT_ETHER) { 1614 if (ifp->if_type != IFT_ETHER) {
1615 panic("%s: impossible", __func__); 1615 panic("%s: impossible", __func__);
1616 } 1616 }
1617 1617
1618 if (m->m_len < sizeof(struct ether_vlan_header) && 1618 if (m->m_len < sizeof(struct ether_vlan_header) &&
1619 (m = m_pullup(m, 1619 (m = m_pullup(m,
1620 sizeof(struct ether_vlan_header))) == NULL) { 1620 sizeof(struct ether_vlan_header))) == NULL) {
1621 printf("%s: no memory for VLAN header, " 1621 printf("%s: no memory for VLAN header, "
1622 "dropping packet.\n", ifp->if_xname); 1622 "dropping packet.\n", ifp->if_xname);
1623 return; 1623 return;
1624 } 1624 }
 1625
 1626 if (m_makewritable(&m, 0,
 1627 sizeof(struct ether_vlan_header), M_DONTWAIT)) {
 1628 m_freem(m);
 1629 if_statinc(ifp, if_ierrors);
 1630 return;
 1631 }
 1632
1625 evl = mtod(m, struct ether_vlan_header *); 1633 evl = mtod(m, struct ether_vlan_header *);
1626 KASSERT(ntohs(evl->evl_encap_proto) == ETHERTYPE_VLAN); 1634 KASSERT(ntohs(evl->evl_encap_proto) == ETHERTYPE_VLAN);
1627 1635
1628 vid = EVL_VLANOFTAG(ntohs(evl->evl_tag)); 1636 vid = EVL_VLANOFTAG(ntohs(evl->evl_tag));
1629 1637
1630 /* 1638 /*
1631 * Restore the original ethertype. We'll remove 1639 * Restore the original ethertype. We'll remove
1632 * the encapsulation after we've found the vlan 1640 * the encapsulation after we've found the vlan
1633 * interface corresponding to the tag. 1641 * interface corresponding to the tag.
1634 */ 1642 */
1635 evl->evl_encap_proto = evl->evl_proto; 1643 evl->evl_encap_proto = evl->evl_proto;
1636 } 1644 }
1637 1645