Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net/npf Switch nptr to uint8_t, and use nbuf_ensure_cont...



details:   https://anonhg.NetBSD.org/src/rev/0780b3ee78d2
branches:  trunk
changeset: 360378:0780b3ee78d2
user:      maxv <maxv%NetBSD.org@localhost>
date:      Thu Mar 08 07:54:14 2018 +0000

description:
Switch nptr to uint8_t, and use nbuf_ensure_contig. Makes us use fewer
magic values.

diffstat:

 sys/net/npf/npf_inet.c |  28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)

diffs (90 lines):

diff -r 6c64bad7980a -r 0780b3ee78d2 sys/net/npf/npf_inet.c
--- a/sys/net/npf/npf_inet.c    Thu Mar 08 07:39:28 2018 +0000
+++ b/sys/net/npf/npf_inet.c    Thu Mar 08 07:54:14 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_inet.c,v 1.38 2018/03/08 07:06:13 maxv Exp $       */
+/*     $NetBSD: npf_inet.c,v 1.39 2018/03/08 07:54:14 maxv Exp $       */
 
 /*-
  * Copyright (c) 2009-2014 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_inet.c,v 1.38 2018/03/08 07:06:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_inet.c,v 1.39 2018/03/08 07:54:14 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -229,7 +229,7 @@
        nbuf_t *nbuf = npc->npc_nbuf;
        const struct tcphdr *th = npc->npc_l4.tcp;
        int topts_len, step;
-       void *nptr;
+       uint8_t *nptr;
        uint8_t val;
        bool ok;
 
@@ -252,7 +252,7 @@
                ok = false;
                goto done;
        }
-       val = *(uint8_t *)nptr;
+       val = *nptr;
 
        switch (val) {
        case TCPOPT_EOL:
@@ -264,43 +264,43 @@
                step = 1;
                break;
        case TCPOPT_MAXSEG:
-               if ((nptr = nbuf_advance(nbuf, 2, 2)) == NULL) {
+               if ((nptr = nbuf_ensure_contig(nbuf, TCPOLEN_MAXSEG)) == NULL) {
                        ok = false;
                        goto done;
                }
                if (mss) {
                        if (*mss) {
-                               memcpy(nptr, mss, sizeof(uint16_t));
+                               memcpy(nptr + 2, mss, sizeof(uint16_t));
                        } else {
-                               memcpy(mss, nptr, sizeof(uint16_t));
+                               memcpy(mss, nptr + 2, sizeof(uint16_t));
                        }
                }
                topts_len -= TCPOLEN_MAXSEG;
-               step = 2;
+               step = TCPOLEN_MAXSEG;
                break;
        case TCPOPT_WINDOW:
                /* TCP Window Scaling (RFC 1323). */
-               if ((nptr = nbuf_advance(nbuf, 2, 1)) == NULL) {
+               if ((nptr = nbuf_ensure_contig(nbuf, TCPOLEN_WINDOW)) == NULL) {
                        ok = false;
                        goto done;
                }
-               val = *(uint8_t *)nptr;
+               val = *(nptr + 2);
                *wscale = (val > TCP_MAX_WINSHIFT) ? TCP_MAX_WINSHIFT : val;
                topts_len -= TCPOLEN_WINDOW;
-               step = 1;
+               step = TCPOLEN_WINDOW;
                break;
        default:
-               if ((nptr = nbuf_advance(nbuf, 1, 1)) == NULL) {
+               if ((nptr = nbuf_ensure_contig(nbuf, 2)) == NULL) {
                        ok = false;
                        goto done;
                }
-               val = *(uint8_t *)nptr;
+               val = *(nptr + 1);
                if (val < 2 || val > topts_len) {
                        ok = false;
                        goto done;
                }
                topts_len -= val;
-               step = val - 1;
+               step = val;
        }
 
        /* Any options left? */



Home | Main Index | Thread Index | Old Index