From owner-svn-src-all@freebsd.org Sat Dec 12 10:26:45 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3D60A4B065A; Sat, 12 Dec 2020 10:26:45 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CtP2s13SPz4jrN; Sat, 12 Dec 2020 10:26:44 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-wm1-x343.google.com with SMTP id c198so9566460wmd.0; Sat, 12 Dec 2020 02:26:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=3nAfmOAjzaizayI2IZLNTh9BexcY0C9STbnfZ2GEQ1M=; b=qIvE3iYjMa68orxWaqPLs6bkt+CwmBoK3KeHMmjZ/SRfY6UUbZq/pTfCxabfe0lNKI FOG7u70rxFmaiHJKaxDWZMD2eBu66BHd/tWLA9y5wACLnpy4YTX8HOSvm9nJEQBw9QoW lHw+Y98trexDbYunHTFsshCSm+5eSkPeTJ+vBXxTcjTazv+hYfhzQZS9hzU5seZ5kSpG LRR/TKL8MB6YewcSOrKVKo4kaKO0VOcSmAqyCLT+MtPit9LNaqP42j3eTB8zMa4gYYKI G25JrZfNI4dljC7YxgXH49l9yktOY6LFmuaxipyMDn66kbihAlNOr0O/Xesn+QcjDuOD G09w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=3nAfmOAjzaizayI2IZLNTh9BexcY0C9STbnfZ2GEQ1M=; b=sWapFpH028PBmHz+RiqfS81TjL4ZOk5HqBN/qcg6CwZCepdDihs3AmYWvoQ/SQFY0Y ujvKTn8kYxhy6rK2K42zKmCUFbUQk3ncdFM9MuliPexsfz8fVIDjhiVkZSYjI6L1eH46 +XMuKWag6i9emWVBCmzEr16V1H8i2zMiwdo8TS0wiVoud2aMaJRcPlZQQ+pumqxChp++ tQqIUnKeZXNzbshU+DpPkzUTS1VTb4xoPvRt1yN82p2NmmOPl3rnHUfSspffZxqhNWrl ibV8TMEIFvsO3qjKSNvBraSRmZQsm11dLsq7VXuUeB3fLFS/nVWI87bog1wHSVKGg/KQ Wwzw== X-Gm-Message-State: AOAM530DLj9XSecZbHCx8eHgqWWNBFHCgfH4YAQJuvFbrDJAjBjMhr+A y7npVU/sINwtE3AYnLjTZLEBVwuZ3BA+fm+GOjArY5DO X-Google-Smtp-Source: ABdhPJyP8frPCj9OBYlb4zDd8k/FtSmQyTvI7Oxrf6Ne1wvTTgX/tQSIrBjHik1pOFDVYhsfGEGjZOAL+L5UeZiblRU= X-Received: by 2002:a1c:6a13:: with SMTP id f19mr17541103wmc.10.1607768803031; Sat, 12 Dec 2020 02:26:43 -0800 (PST) MIME-Version: 1.0 Received: by 2002:adf:f811:0:0:0:0:0 with HTTP; Sat, 12 Dec 2020 02:26:41 -0800 (PST) In-Reply-To: <202012112357.0BBNvUn0069609@repo.freebsd.org> References: <202012112357.0BBNvUn0069609@repo.freebsd.org> From: Mateusz Guzik Date: Sat, 12 Dec 2020 11:26:41 +0100 Message-ID: Subject: Re: svn commit: r368571 - head/sys/netpfil/ipfw To: "Alexander V. Chernikov" Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4CtP2s13SPz4jrN X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Dec 2020 10:26:45 -0000 This breaks LINT-NOINET6: linking kernel ld: error: undefined symbol: fib6_lookup_rt >>> referenced by ip_fw_table_algo.c >>> ip_fw_table_algo.o:(ta_find_kfib_tentry) >>> did you mean: fib4_lookup_rt On 12/12/20, Alexander V. Chernikov wrote: > Author: melifaro > Date: Fri Dec 11 23:57:30 2020 > New Revision: 368571 > URL: https://svnweb.freebsd.org/changeset/base/368571 > > Log: > ipfw kfib algo: Use rt accessors instead of accessing rib/rtentry > directly. > > This removes assumptions on prefix storage and rtentry layout > from an external code. > > Differential Revision: https://reviews.freebsd.org/D27450 > > Modified: > head/sys/netpfil/ipfw/ip_fw_table_algo.c > > Modified: head/sys/netpfil/ipfw/ip_fw_table_algo.c > ============================================================================== > --- head/sys/netpfil/ipfw/ip_fw_table_algo.c Fri Dec 11 22:52:20 > 2020 (r368570) > +++ head/sys/netpfil/ipfw/ip_fw_table_algo.c Fri Dec 11 23:57:30 > 2020 (r368571) > @@ -52,7 +52,7 @@ __FBSDID("$FreeBSD$"); > #include > #include > #include > -#include > +#include > > #include > #include > @@ -3781,11 +3781,10 @@ static int ta_init_kfib(struct ip_fw_chain *ch, void > * > static void ta_destroy_kfib(void *ta_state, struct table_info *ti); > static void ta_dump_kfib_tinfo(void *ta_state, struct table_info *ti, > ipfw_ta_tinfo *tinfo); > -static int contigmask(uint8_t *p, int len); > static int ta_dump_kfib_tentry(void *ta_state, struct table_info *ti, void > *e, > ipfw_obj_tentry *tent); > -static int ta_dump_kfib_tentry_int(struct sockaddr *paddr, > - struct sockaddr *pmask, ipfw_obj_tentry *tent); > +static int ta_dump_kfib_tentry_int(int familt, const struct rtentry *rt, > + ipfw_obj_tentry *tent); > static int ta_find_kfib_tentry(void *ta_state, struct table_info *ti, > ipfw_obj_tentry *tent); > static void ta_foreach_kfib(void *ta_state, struct table_info *ti, > @@ -3900,84 +3899,35 @@ ta_dump_kfib_tinfo(void *ta_state, struct table_info > * > tinfo->flags = IPFW_TATFLAGS_AFDATA; > tinfo->taclass4 = IPFW_TACLASS_RADIX; > tinfo->count4 = 0; > - tinfo->itemsize4 = sizeof(struct rtentry); > + tinfo->itemsize4 = 128; /* table is readonly, value does not matter */ > tinfo->taclass6 = IPFW_TACLASS_RADIX; > tinfo->count6 = 0; > - tinfo->itemsize6 = sizeof(struct rtentry); > + tinfo->itemsize6 = 128; > } > > static int > -contigmask(uint8_t *p, int len) > -{ > - int i, n; > - > - for (i = 0; i < len ; i++) > - if ( (p[i/8] & (1 << (7 - (i%8)))) == 0) /* first bit unset */ > - break; > - for (n= i + 1; n < len; n++) > - if ( (p[n/8] & (1 << (7 - (n % 8)))) != 0) > - return (-1); /* mask not contiguous */ > - return (i); > -} > - > -static int > -ta_dump_kfib_tentry(void *ta_state, struct table_info *ti, void *e, > +ta_dump_kfib_tentry_int(int family, const struct rtentry *rt, > ipfw_obj_tentry *tent) > { > - struct rtentry *rte; > + uint32_t scopeid; > + int plen; > > - rte = (struct rtentry *)e; > - > - return ta_dump_kfib_tentry_int(rt_key(rte), rt_mask(rte), tent); > -} > - > -static int > -ta_dump_kfib_tentry_int(struct sockaddr *paddr, struct sockaddr *pmask, > - ipfw_obj_tentry *tent) > -{ > #ifdef INET > - struct sockaddr_in *addr, *mask; > -#endif > -#ifdef INET6 > - struct sockaddr_in6 *addr6, *mask6; > -#endif > - int len; > - > - len = 0; > - > - /* Guess IPv4/IPv6 radix by sockaddr family */ > -#ifdef INET > - if (paddr->sa_family == AF_INET) { > - addr = (struct sockaddr_in *)paddr; > - mask = (struct sockaddr_in *)pmask; > - tent->k.addr.s_addr = addr->sin_addr.s_addr; > - len = 32; > - if (mask != NULL) > - len = contigmask((uint8_t *)&mask->sin_addr, 32); > - if (len == -1) > - len = 0; > - tent->masklen = len; > + if (family == AF_INET) { > + rt_get_inet_prefix_plen(rt, &tent->k.addr, &plen, &scopeid); > + tent->masklen = plen; > tent->subtype = AF_INET; > - tent->v.kidx = 0; /* Do we need to put GW here? */ > + tent->v.kidx = 0; > } > #endif > -#ifdef INET6 > - if (paddr->sa_family == AF_INET6) { > - addr6 = (struct sockaddr_in6 *)paddr; > - mask6 = (struct sockaddr_in6 *)pmask; > - memcpy(&tent->k.addr6, &addr6->sin6_addr, > - sizeof(struct in6_addr)); > - len = 128; > - if (mask6 != NULL) > - len = contigmask((uint8_t *)&mask6->sin6_addr, 128); > - if (len == -1) > - len = 0; > - tent->masklen = len; > +#ifdef INET > + if (family == AF_INET6) { > + rt_get_inet6_prefix_plen(rt, &tent->k.addr6, &plen, &scopeid); > + tent->masklen = plen; > tent->subtype = AF_INET6; > tent->v.kidx = 0; > } > #endif > - > return (0); > } > > @@ -3985,66 +3935,61 @@ static int > ta_find_kfib_tentry(void *ta_state, struct table_info *ti, > ipfw_obj_tentry *tent) > { > - struct rt_addrinfo info; > - struct sockaddr_in6 key6, dst6, mask6; > - struct sockaddr *dst, *key, *mask; > + struct rtentry *rt; > + struct route_nhop_data rnd; > + struct epoch_tracker et; > + int error; > > - /* Prepare sockaddr for prefix/mask and info */ > - bzero(&dst6, sizeof(dst6)); > - dst6.sin6_len = sizeof(dst6); > - dst = (struct sockaddr *)&dst6; > - bzero(&mask6, sizeof(mask6)); > - mask6.sin6_len = sizeof(mask6); > - mask = (struct sockaddr *)&mask6; > - > - bzero(&info, sizeof(info)); > - info.rti_info[RTAX_DST] = dst; > - info.rti_info[RTAX_NETMASK] = mask; > - > - /* Prepare the lookup key */ > - bzero(&key6, sizeof(key6)); > - key6.sin6_family = tent->subtype; > - key = (struct sockaddr *)&key6; > - > + NET_EPOCH_ENTER(et); > if (tent->subtype == AF_INET) { > - ((struct sockaddr_in *)&key6)->sin_addr = tent->k.addr; > - key6.sin6_len = sizeof(struct sockaddr_in); > + rt = fib4_lookup_rt(ti->data, tent->k.addr, 0, 0, &rnd); > } else { > - key6.sin6_addr = tent->k.addr6; > - key6.sin6_len = sizeof(struct sockaddr_in6); > + rt = fib6_lookup_rt(ti->data, &tent->k.addr6, 0, 0, &rnd); > } > + if (rt != NULL) > + error = ta_dump_kfib_tentry_int(tent->subtype, rt, tent); > + else > + error = ENOENT; > + NET_EPOCH_EXIT(et); > > - if (rib_lookup_info(ti->data, key, 0, 0, &info) != 0) > - return (ENOENT); > - if ((info.rti_addrs & RTA_NETMASK) == 0) > - mask = NULL; > + return (error); > +} > > - ta_dump_kfib_tentry_int(dst, mask, tent); > +struct kfib_dump_arg { > + struct rtentry *rt; > + int family; > + ta_foreach_f *f; > + void *arg; > +}; > > - return (0); > +static int > +ta_dump_kfib_tentry(void *ta_state, struct table_info *ti, void *e, > + ipfw_obj_tentry *tent) > +{ > + struct kfib_dump_arg *karg = (struct kfib_dump_arg *)e; > + > + return (ta_dump_kfib_tentry_int(karg->family, karg->rt, tent)); > } > > +static int > +walk_wrapper_f(struct rtentry *rt, void *arg) > +{ > + struct kfib_dump_arg *karg = (struct kfib_dump_arg *)arg; > + > + karg->rt = rt; > + return (karg->f(karg, karg->arg)); > +} > + > static void > ta_foreach_kfib(void *ta_state, struct table_info *ti, ta_foreach_f *f, > void *arg) > { > - RIB_RLOCK_TRACKER; > - struct rib_head *rh; > - int error; > + struct kfib_dump_arg karg = { .f = f, .arg = arg }; > > - rh = rt_tables_get_rnh(ti->data, AF_INET); > - if (rh != NULL) { > - RIB_RLOCK(rh); > - error = rh->rnh_walktree(&rh->head, (walktree_f_t *)f, arg); > - RIB_RUNLOCK(rh); > - } > - > - rh = rt_tables_get_rnh(ti->data, AF_INET6); > - if (rh != NULL) { > - RIB_RLOCK(rh); > - error = rh->rnh_walktree(&rh->head, (walktree_f_t *)f, arg); > - RIB_RUNLOCK(rh); > - } > + karg.family = AF_INET; > + rib_walk(ti->data, AF_INET, false, walk_wrapper_f, &karg); > + karg.family = AF_INET6; > + rib_walk(ti->data, AF_INET6, false, walk_wrapper_f, &karg); > } > > struct table_algo addr_kfib = { > _______________________________________________ > svn-src-all@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/svn-src-all > To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org" > -- Mateusz Guzik