Module Name:    src
Committed By:   martin
Date:           Wed Apr 11 14:15:45 UTC 2018

Modified Files:
        src/sys/net [netbsd-8]: if_l2tp.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #730):

        sys/net/if_l2tp.c: revision 1.22
        sys/net/if_l2tp.c: revision 1.23

Improve comment. Pointed out by maxv@n.o, thanks.

Fix previous my mistake and odd unaligned case. Pointed out by maxv@n.o, thanks.
It must be rare case to be required this copy routine...


To generate a diff of this commit:
cvs rdiff -u -r1.11.2.6 -r1.11.2.7 src/sys/net/if_l2tp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.11.2.6 src/sys/net/if_l2tp.c:1.11.2.7
--- src/sys/net/if_l2tp.c:1.11.2.6	Mon Apr  9 13:40:20 2018
+++ src/sys/net/if_l2tp.c	Wed Apr 11 14:15:45 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.11.2.6 2018/04/09 13:40:20 bouyer Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.11.2.7 2018/04/11 14:15:45 martin Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11.2.6 2018/04/09 13:40:20 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11.2.7 2018/04/11 14:15:45 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -477,11 +477,16 @@ l2tp_input(struct mbuf *m, struct ifnet 
 		return;
 	}
 
+	/*
+	 * If the head of the payload is not aligned, align it.
+	 */
 	addr = mtod(m, vaddr_t);
-	if ((addr & 0x03) == 0) {
+	if ((addr & 0x03) != 0x2) {
 		/* copy and align head of payload */
 		struct mbuf *m_head;
 		int copy_length;
+		u_int pad = roundup(sizeof(struct ether_header), 4)
+			- sizeof(struct ether_header);
 
 #define L2TP_COPY_LENGTH		60
 
@@ -504,7 +509,19 @@ l2tp_input(struct mbuf *m, struct ifnet 
 		}
 		M_COPY_PKTHDR(m_head, m);
 
-		MH_ALIGN(m_head, L2TP_COPY_LENGTH);
+		/*
+		 * m_head should be:
+		 *                             L2TP_COPY_LENGTH
+		 *                          <-  + roundup(pad, 4) - pad ->
+		 *   +-------+--------+-----+--------------+-------------+
+		 *   | m_hdr | pkthdr | ... | ether header |   payload   |
+		 *   +-------+--------+-----+--------------+-------------+
+		 *                          ^              ^
+		 *                          m_data         4 byte aligned
+		 */
+		MH_ALIGN(m_head, L2TP_COPY_LENGTH + roundup(pad, 4));
+		m_head->m_data += pad;
+
 		memcpy(mtod(m_head, void *), mtod(m, void *), copy_length);
 		m_head->m_len = copy_length;
 		m->m_data += copy_length;

Reply via email to