Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet Refactor ip_encap.[ch]



details:   https://anonhg.NetBSD.org/src/rev/33cdbabe69f9
branches:  trunk
changeset: 372553:33cdbabe69f9
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Wed Dec 07 08:33:02 2022 +0000

description:
Refactor ip_encap.[ch]

    - remove encap_attach() which is no longer used
    - remove USE_RADIX code in ip_encap.c, which is used for
      encap_attach() only
    - remove mask members in encaptab

diffstat:

 sys/netinet/ip_encap.c |  425 +-----------------------------------------------
 sys/netinet/ip_encap.h |   17 +-
 2 files changed, 14 insertions(+), 428 deletions(-)

diffs (truncated from 614 to 300 lines):

diff -r a9c566161c5d -r 33cdbabe69f9 sys/netinet/ip_encap.c
--- a/sys/netinet/ip_encap.c    Wed Dec 07 08:30:15 2022 +0000
+++ b/sys/netinet/ip_encap.c    Wed Dec 07 08:33:02 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_encap.c,v 1.76 2022/12/07 08:28:46 knakahara Exp $  */
+/*     $NetBSD: ip_encap.c,v 1.77 2022/12/07 08:33:02 knakahara Exp $  */
 /*     $KAME: ip_encap.c,v 1.73 2001/10/02 08:30:58 itojun Exp $       */
 
 /*
@@ -57,18 +57,8 @@
  */
 /* XXX is M_NETADDR correct? */
 
-/*
- * With USE_RADIX the code will use radix table for tunnel lookup, for
- * tunnels registered with encap_attach() with a addr/mask pair.
- * Faster on machines with thousands of tunnel registerations (= interfaces).
- *
- * The code assumes that radix table code can handle non-continuous netmask,
- * as it will pass radix table memory region with (src + dst) sockaddr pair.
- */
-#define USE_RADIX
-
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.76 2022/12/07 08:28:46 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.77 2022/12/07 08:33:02 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -128,13 +118,6 @@
 static int encap_add(struct encaptab *);
 static int encap_remove(struct encaptab *);
 static void encap_afcheck(int, const struct sockaddr *, const struct sockaddr *);
-#ifdef USE_RADIX
-static struct radix_node_head *encap_rnh(int);
-static int mask_matchlen(const struct sockaddr *);
-#else
-static int mask_match(const struct encaptab *, const struct sockaddr *,
-               const struct sockaddr *);
-#endif
 static void encap_key_init(struct encap_key *, const struct sockaddr *,
     const struct sockaddr *);
 static void encap_key_inc(struct encap_key *);
@@ -158,11 +141,6 @@
        struct lwp      *busy;
 } encap_whole __cacheline_aligned;
 
-#ifdef USE_RADIX
-struct radix_node_head *encap_head[2]; /* 0 for AF_INET, 1 for AF_INET6 */
-static bool encap_head_updating = false;
-#endif
-
 static thmap_t *encap_map[2];  /* 0 for AF_INET, 1 for AF_INET6 */
 
 static bool encap_initialized = false;
@@ -205,18 +183,6 @@
        PSLIST_INIT(&encap_table);
 #endif
 
-#ifdef USE_RADIX
-       /*
-        * initialize radix lookup table when the radix subsystem is inited.
-        */
-       rn_delayedinit((void *)&encap_head[0],
-           sizeof(struct sockaddr_pack) << 3);
-#ifdef INET6
-       rn_delayedinit((void *)&encap_head[1],
-           sizeof(struct sockaddr_pack) << 3);
-#endif
-#endif
-
        encap_map[0] = thmap_create(0, NULL, THMAP_NOCOPY);
 #ifdef INET6
        encap_map[1] = thmap_create(0, NULL, THMAP_NOCOPY);
@@ -233,10 +199,6 @@
        struct encaptab *ep, *match;
        int prio, matchprio;
        int s;
-#ifdef USE_RADIX
-       struct radix_node_head *rnh = encap_rnh(AF_INET);
-       struct radix_node *rn;
-#endif
        thmap_t *emap = encap_map[0];
        struct encap_key key;
 
@@ -260,26 +222,6 @@
        matchprio = 0;
 
        s = pserialize_read_enter();
-#ifdef USE_RADIX
-       if (encap_head_updating) {
-               /*
-                * Update in progress. Do nothing.
-                */
-               pserialize_read_exit(s);
-               return NULL;
-       }
-
-       rn = rnh->rnh_matchaddr((void *)&pack, rnh);
-       if (rn && (rn->rn_flags & RNF_ROOT) == 0) {
-               struct encaptab *encapp = (struct encaptab *)rn;
-
-               psref_acquire(match_psref, &encapp->psref,
-                   encaptab.elem_class);
-               match = encapp;
-               matchprio = mask_matchlen(match->srcmask) +
-                   mask_matchlen(match->dstmask);
-       }
-#endif
 
        encap_key_init(&key, sintosa(&pack.mine), sintosa(&pack.yours));
        while ((ep = thmap_get(emap, &key, sizeof(key))) != NULL) {
@@ -335,42 +277,21 @@
 
                psref_acquire(&elem_psref, &ep->psref,
                    encaptab.elem_class);
-               if (ep->func) {
-                       pserialize_read_exit(s);
-                       /* ep->func is sleepable. e.g. rtalloc1 */
-                       prio = (*ep->func)(m, off, proto, ep->arg);
-                       s = pserialize_read_enter();
-               } else {
-#ifdef USE_RADIX
-                       psref_release(&elem_psref, &ep->psref,
-                           encaptab.elem_class);
-                       continue;
-#else
-                       prio = mask_match(ep, (struct sockaddr *)&pack.mine,
-                           (struct sockaddr *)&pack.yours);
-#endif
-               }
+               pserialize_read_exit(s);
+               /* ep->func is sleepable. e.g. rtalloc1 */
+               prio = (*ep->func)(m, off, proto, ep->arg);
+               s = pserialize_read_enter();
 
                /*
                 * We prioritize the matches by using bit length of the
-                * matches.  mask_match() and user-supplied matching function
+                * matches.  user-supplied matching function
                 * should return the bit length of the matches (for example,
                 * if both src/dst are matched for IPv4, 64 should be returned).
                 * 0 or negative return value means "it did not match".
                 *
-                * The question is, since we have two "mask" portion, we
-                * cannot really define total order between entries.
-                * For example, which of these should be preferred?
-                * mask_match() returns 48 (32 + 16) for both of them.
-                *      src=3ffe::/16, dst=3ffe:501::/32
-                *      src=3ffe:501::/32, dst=3ffe::/16
-                *
                 * We need to loop through all the possible candidates
                 * to get the best match - the search takes O(n) for
                 * n attachments (i.e. interfaces).
-                *
-                * For radix-based lookup, I guess source takes precedence.
-                * See rn_{refines,lexobetter} for the correct answer.
                 */
                if (prio <= 0) {
                        psref_release(&elem_psref, &ep->psref,
@@ -440,10 +361,6 @@
        int prio, matchprio;
        int s;
        struct encaptab *ep, *match;
-#ifdef USE_RADIX
-       struct radix_node_head *rnh = encap_rnh(AF_INET6);
-       struct radix_node *rn;
-#endif
        thmap_t *emap = encap_map[1];
        struct encap_key key;
 
@@ -467,26 +384,6 @@
        matchprio = 0;
 
        s = pserialize_read_enter();
-#ifdef USE_RADIX
-       if (encap_head_updating) {
-               /*
-                * Update in progress. Do nothing.
-                */
-               pserialize_read_exit(s);
-               return NULL;
-       }
-
-       rn = rnh->rnh_matchaddr((void *)&pack, rnh);
-       if (rn && (rn->rn_flags & RNF_ROOT) == 0) {
-               struct encaptab *encapp = (struct encaptab *)rn;
-
-               psref_acquire(match_psref, &encapp->psref,
-                   encaptab.elem_class);
-               match = encapp;
-               matchprio = mask_matchlen(match->srcmask) +
-                   mask_matchlen(match->dstmask);
-       }
-#endif
 
        encap_key_init(&key, sin6tosa(&pack.mine), sin6tosa(&pack.yours));
        while ((ep = thmap_get(emap, &key, sizeof(key))) != NULL) {
@@ -542,21 +439,10 @@
                psref_acquire(&elem_psref, &ep->psref,
                    encaptab.elem_class);
 
-               if (ep->func) {
-                       pserialize_read_exit(s);
-                       /* ep->func is sleepable. e.g. rtalloc1 */
-                       prio = (*ep->func)(m, off, proto, ep->arg);
-                       s = pserialize_read_enter();
-               } else {
-#ifdef USE_RADIX
-                       psref_release(&elem_psref, &ep->psref,
-                           encaptab.elem_class);
-                       continue;
-#else
-                       prio = mask_match(ep, (struct sockaddr *)&pack.mine,
-                           (struct sockaddr *)&pack.yours);
-#endif
-               }
+               pserialize_read_exit(s);
+               /* ep->func is sleepable. e.g. rtalloc1 */
+               prio = (*ep->func)(m, off, proto, ep->arg);
+               s = pserialize_read_enter();
 
                /* see encap4_lookup() for issues here */
                if (prio <= 0) {
@@ -624,82 +510,24 @@
 }
 #endif
 
-/*
- * XXX
- * The encaptab list and the rnh radix tree must be manipulated atomically.
- */
 static int
 encap_add(struct encaptab *ep)
 {
-#ifdef USE_RADIX
-       struct radix_node_head *rnh = encap_rnh(ep->af);
-#endif
 
        KASSERT(encap_lock_held());
 
-#ifdef USE_RADIX
-       if (!ep->func && rnh) {
-               /* Disable access to the radix tree for reader. */
-               encap_head_updating = true;
-               /* Wait for all readers to drain. */
-               pserialize_perform(encaptab.psz);
-
-               if (!rnh->rnh_addaddr((void *)ep->addrpack,
-                   (void *)ep->maskpack, rnh, ep->nodes)) {
-                       encap_head_updating = false;
-                       return EEXIST;
-               }
-
-               /*
-                * The ep added to the radix tree must be skipped while
-                * encap[46]_lookup walks encaptab list. In other words,
-                * encap_add() does not need to care whether the ep has
-                * been added encaptab list or not yet.
-                * So, we can re-enable access to the radix tree for now.
-                */
-               encap_head_updating = false;
-       }
-#endif
        PSLIST_WRITER_INSERT_HEAD(&encap_table, ep, chain);
 
        return 0;
 }
 
-/*
- * XXX
- * The encaptab list and the rnh radix tree must be manipulated atomically.
- */
 static int
 encap_remove(struct encaptab *ep)
 {
-#ifdef USE_RADIX
-       struct radix_node_head *rnh = encap_rnh(ep->af);
-#endif
        int error = 0;
 
        KASSERT(encap_lock_held());
 
-#ifdef USE_RADIX
-       if (!ep->func && rnh) {
-               /* Disable access to the radix tree for reader. */
-               encap_head_updating = true;
-               /* Wait for all readers to drain. */
-               pserialize_perform(encaptab.psz);
-
-               if (!rnh->rnh_deladdr((void *)ep->addrpack,
-                   (void *)ep->maskpack, rnh))
-                       error = ESRCH;
-
-               /*
-                * The ep added to the radix tree must be skipped while
-                * encap[46]_lookup walks encaptab list. In other words,
-                * encap_add() does not need to care whether the ep has
-                * been added encaptab list or not yet.
-                * So, we can re-enable access to the radix tree for now.



Home | Main Index | Thread Index | Old Index