From owner-dev-commits-src-all@freebsd.org Tue Feb 16 21:47:07 2021 Return-Path: Delivered-To: dev-commits-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 C33AB54B560; Tue, 16 Feb 2021 21:47:07 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (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 4DgF1R4xzZz3kkZ; Tue, 16 Feb 2021 21:47:07 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-wm1-x32f.google.com with SMTP id m1so163633wml.2; Tue, 16 Feb 2021 13:47:07 -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:content-transfer-encoding; bh=njT4Zgupkr0NOtPtidswr384Yey2uGh9yifu7Bsg6M0=; b=NOmPhc09zKVokoXWCWzoN6DbKnHKSwsCq8+RLsqTiXV49pXV/LXUykTrwgW52H0kpj z3h+4EjzYRB8RDJsH/h/EcjsPGa4UXJOMPf79aldihggyW93SlMmQysZFxsQ/mEOQOFN feZ2NLrki/QOLxwnxgK8H+LS55i3P/ovPidZC4AaZWEHBfJ9SWr3MHz6fO0ScRfX+faa oAHIwTIZsHHDAITEJY1F1Ueq/6v5BN2VzQmPVgX4LQu51R67gI4TzjnoaS56d8aX5p5O PiBpOwM/FSSuuXIV/ebYzFU6HNS6pWnJZiQ9L35UgBM6OdcXoVYxe9uKhxqTtZ2KBMR8 Ajjg== 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:content-transfer-encoding; bh=njT4Zgupkr0NOtPtidswr384Yey2uGh9yifu7Bsg6M0=; b=cZ4mxGSjaJgQ0vacnrzeeoUX3XWDOn8sVCtocPFGmlPOpWu36Scqj5Y84xZnqhxHmk Jqokmywq24YvEhTioyQPvhHwYDSNRXHyhHqXPJoZat7CA2GQw08M9Dj9AkaBAV9CaAU1 Cse7UYWOnbM/pjWyflvNE9R0KdAqZTWAW2pdTNT+LDaqAhGqYJ+VlqqUSpAufdNgyyv9 9N/flKbl3zZ+ySRLkPF+1T+Rd2rvz5G6o5U7FrbwiuC4l6m1CUT4LZkOnF5QzkLSjIvl 0nSKqEhPu0TG9HAEXG/SP/esIZIC3tCGgV/WemEac1cM0jL1x9OBjkVZCcfPfQf14YX3 VcQA== X-Gm-Message-State: AOAM532dLhLav5jNvJXpL1UHeEUf4O8IrVhnC14RO1+wuIv2fwjq4ahZ RjcNBLjWs7+wyY6mlY8WNtOqZ0fF8LfEBmNOWgymQ15g X-Google-Smtp-Source: ABdhPJwHpikK7Je3VsVdj5r10gP5dIi2ixCGRYB9WHFUjOnkaRRaqJVCHEpWWzwhRWkq55MZORwaH5j2tEWoeV63F6g= X-Received: by 2002:a7b:c397:: with SMTP id s23mr44777wmj.10.1613512025470; Tue, 16 Feb 2021 13:47:05 -0800 (PST) MIME-Version: 1.0 Received: by 2002:adf:e406:0:0:0:0:0 with HTTP; Tue, 16 Feb 2021 13:47:03 -0800 (PST) In-Reply-To: <290641613510357@mail.yandex.ru> References: <202102162031.11GKV0T6060307@gitrepo.freebsd.org> <290641613510357@mail.yandex.ru> From: Mateusz Guzik Date: Tue, 16 Feb 2021 22:47:03 +0100 Message-ID: Subject: Re: git: 2fe5a79425c7 - main - Fix dst/netmask handling in routing socket code. To: "Alexander V. Chernikov" Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4DgF1R4xzZz3kkZ X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Feb 2021 21:47:07 -0000 In this context I meant NOINET and NOINET6 Anyhow I see the following: sys/net/rtsock.c:1427:2: error: implicit declaration of function 'IN6_MASK_ADDR' is invalid in C99 [-Werror,-Wimplicit-function-declaration] IN6_MASK_ADDR(&dst_sa->sin6_addr, &mask); ^ On 2/16/21, Alexander V. Chernikov wrote: > 16.02.2021, 20:43, "Mateusz Guzik" : >> This breaks the built at least without INET6. > It would help if you could share the actual build error. > I see -Wunused for 2 function (which I will fix soon), but I'm not sure i= f > that's the error you're running into. >> >> can you please start testing your patches on NOINET kernels > Well, it actually builds for me: > -------------------------------------------------------------- >>>> Kernel build for LINT-NOINET completed on Tue Feb 16 21:21:39 UTC 2021 > -------------------------------------------------------------- >>>> Kernel(s) LINT-NOINET built in 28 seconds, ncpu: 2, make -j6 > -------------------------------------------------------------- > >> >> On 2/16/21, Alexander V. Chernikov wrote: >>> =C2=A0The branch main has been updated by melifaro: >>> >>> =C2=A0URL: >>> =C2=A0https://cgit.FreeBSD.org/src/commit/?id=3D2fe5a79425c79f7b828acd9= 1da66d97230925fc8 >>> >>> =C2=A0commit 2fe5a79425c79f7b828acd91da66d97230925fc8 >>> =C2=A0Author: Alexander V. Chernikov >>> =C2=A0AuthorDate: 2021-02-16 20:30:04 +0000 >>> =C2=A0Commit: Alexander V. Chernikov >>> =C2=A0CommitDate: 2021-02-16 20:30:04 +0000 >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Fix dst/netmask handling in routing socke= t code. >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Traditionally routing socket code did alm= ost zero checks on >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0the input message except for the mo= st basic size checks. >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0This resulted in the unclear KPI boundary= for the routing system >>> code >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(`rtrequest*` and now `rib_action()= `) w.r.t message validness. >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Multiple potential problems and nuances e= xists: >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* Host bits in RTAX_DST sockaddr. Existin= g applications do send >>> =C2=A0prefixes >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0with hostbits uncleared. Even `rout= e(8)` does this, as they hope >>> the >>> =C2=A0kernel >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0would do the job of fixing it. Code= inside `rib_action()` needs to >>> =C2=A0handle >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0it on its own (see `rt_maskedcopy()= ` ugly hack). >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* There are multiple way of adding the ho= st route: it can be DST >>> =C2=A0without >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0netmask or DST with /32(/128) netma= sk. Also, RTF_HOST has to be >>> set >>> =C2=A0correspondingly. >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Currently, these 2 options create 2= DIFFERENT routes in the >>> kernel. >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* no sockaddr length/content checking for= the "secondary" fields >>> exists: >>> =C2=A0nothing >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0stops rtsock application to send so= ckaddr_in with length of 25 >>> (instead >>> =C2=A0of 16). >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Kernel will accept it, install to R= IB as is and propagate to all >>> rtsock >>> =C2=A0consumers, >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0potentially triggering bugs in thei= r code. Same goes for sin_port, >>> =C2=A0sin_zero, etc. >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0The goal of this change is to make rtsock= verify all sockaddr and >>> prefix >>> =C2=A0consistency. >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Said differently, `rib_action()` or inter= nals should NOT require to >>> =C2=A0change any of the >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0sockaddrs supplied by `rt_addrinfo`= structure due to >>> incorrectness. >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0To be more specific, this change implemen= ts the following: >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* sockaddr cleanup/validation check is ad= ded immediately after >>> getting >>> =C2=A0sockaddrs from rtm. >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* Per-family dst/netmask checks clears ho= st bits in dst and zeros >>> all >>> =C2=A0dst/netmask "secondary" fields. >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* The same netmask checking code converts= /32(/128) netmasks to >>> "host" >>> =C2=A0route case >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(NULL netmask, RTF_HOST), removing = the dualism. >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* Instead of allowing ANY "known" sockadd= r families (0<..>> allow >>> =C2=A0only actually >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0supported ones (inet, inet6, link). >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* Automatically convert `sockaddr_sdl` (A= F_LINK) gateways to >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0`sockaddr_sdl_short`. >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Reported by: Guy Yur >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Reviewed By: donner >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Differential Revision: https://reviews.fr= eebsd.org/D28668 >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0MFC after: 3 days >>> =C2=A0--- >>> =C2=A0=C2=A0sys/net/rtsock.c | 201 >>> =C2=A0+++++++++++++++++++++++++++++++++- >>> =C2=A0=C2=A0tests/sys/net/routing/rtsock_common.h | 4 - >>> =C2=A0=C2=A02 files changed, 195 insertions(+), 10 deletions(-) >>> >>> =C2=A0diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c >>> =C2=A0index 3a98b366dfc3..40ce62c77c2a 100644 >>> =C2=A0--- a/sys/net/rtsock.c >>> =C2=A0+++ b/sys/net/rtsock.c >>> =C2=A0@@ -70,6 +70,7 @@ >>> =C2=A0=C2=A0#include >>> =C2=A0=C2=A0#include >>> =C2=A0=C2=A0#ifdef INET6 >>> =C2=A0+#include >>> =C2=A0=C2=A0#include >>> =C2=A0=C2=A0#include >>> =C2=A0=C2=A0#endif >>> =C2=A0@@ -173,6 +174,7 @@ static int rtsock_msg_buffer(int type, struct >>> =C2=A0rt_addrinfo *rtinfo, >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0struct walkarg *w, int *plen); >>> =C2=A0=C2=A0static int rt_xaddrs(caddr_t cp, caddr_t cplim, >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0struct rt_addrinfo *rtinfo); >>> =C2=A0+static int cleanup_xaddrs(struct rt_addrinfo *info); >>> =C2=A0=C2=A0static int sysctl_dumpentry(struct rtentry *rt, void *vw); >>> =C2=A0=C2=A0static int sysctl_dumpnhop(struct rtentry *rt, struct nhop_= object *nh, >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0uint32_t weight, struct walkarg *w); >>> =C2=A0@@ -636,11 +638,9 @@ fill_addrinfo(struct rt_msghdr *rtm, int len= , >>> u_int >>> =C2=A0fibnum, struct rt_addrinfo * >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return (EINVAL); >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0info->rti_f= lags =3D rtm->rtm_flags; >>> =C2=A0- if (info->rti_info[RTAX_DST] =3D=3D NULL || >>> =C2=A0- info->rti_info[RTAX_DST]->sa_family >=3D AF_MAX || >>> =C2=A0- (info->rti_info[RTAX_GATEWAY] !=3D NULL && >>> =C2=A0- info->rti_info[RTAX_GATEWAY]->sa_family >=3D AF_MAX)) >>> =C2=A0- return (EINVAL); >>> =C2=A0+ error =3D cleanup_xaddrs(info); >>> =C2=A0+ if (error !=3D 0) >>> =C2=A0+ return (error); >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0saf =3D inf= o->rti_info[RTAX_DST]->sa_family; >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0/* >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* Ver= ify that the caller has the appropriate privilege; >>> RTM_GET >>> =C2=A0@@ -739,7 +739,14 @@ handle_rtm_get(struct rt_addrinfo *info, u_i= nt >>> fibnum, >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0RIB_RLOCK(r= nh); >>> >>> =C2=A0- if (info->rti_info[RTAX_NETMASK] =3D=3D NULL) { >>> =C2=A0+ /* >>> =C2=A0+ * By (implicit) convention host route (one without netmask) >>> =C2=A0+ * means longest-prefix-match request and the route with netmask >>> =C2=A0+ * means exact-match lookup. >>> =C2=A0+ * As cleanup_xaddrs() cleans up info flags&addrs for the /32,/1= 28 >>> =C2=A0+ * prefixes, use original data to check for the netmask presence= . >>> =C2=A0+ */ >>> =C2=A0+ if ((rtm->rtm_addrs & RTA_NETMASK) =3D=3D 0) { >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0/* >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* Provide longest prefix match= for >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* address lookup (no mask). >>> =C2=A0@@ -1286,6 +1293,188 @@ rt_xaddrs(caddr_t cp, caddr_t cplim, stru= ct >>> =C2=A0rt_addrinfo *rtinfo) >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return (0); >>> =C2=A0=C2=A0} >>> >>> =C2=A0+static inline void >>> =C2=A0+fill_sockaddr_inet(struct sockaddr_in *sin, struct in_addr addr) >>> =C2=A0+{ >>> =C2=A0+ >>> =C2=A0+ const struct sockaddr_in nsin =3D { >>> =C2=A0+ .sin_family =3D AF_INET, >>> =C2=A0+ .sin_len =3D sizeof(struct sockaddr_in), >>> =C2=A0+ .sin_addr =3D addr, >>> =C2=A0+ }; >>> =C2=A0+ *sin =3D nsin; >>> =C2=A0+} >>> =C2=A0+ >>> =C2=A0+static inline void >>> =C2=A0+fill_sockaddr_inet6(struct sockaddr_in6 *sin6, const struct in6_= addr >>> =C2=A0*addr6, >>> =C2=A0+ uint32_t scopeid) >>> =C2=A0+{ >>> =C2=A0+ >>> =C2=A0+ const struct sockaddr_in6 nsin6 =3D { >>> =C2=A0+ .sin6_family =3D AF_INET6, >>> =C2=A0+ .sin6_len =3D sizeof(struct sockaddr_in6), >>> =C2=A0+ .sin6_addr =3D *addr6, >>> =C2=A0+ .sin6_scope_id =3D scopeid, >>> =C2=A0+ }; >>> =C2=A0+ *sin6 =3D nsin6; >>> =C2=A0+} >>> =C2=A0+ >>> =C2=A0+static int >>> =C2=A0+cleanup_xaddrs_gateway(struct rt_addrinfo *info) >>> =C2=A0+{ >>> =C2=A0+ struct sockaddr *gw =3D info->rti_info[RTAX_GATEWAY]; >>> =C2=A0+ >>> =C2=A0+ switch (gw->sa_family) { >>> =C2=A0+#ifdef INET >>> =C2=A0+ case AF_INET: >>> =C2=A0+ { >>> =C2=A0+ struct sockaddr_in *gw_sin =3D (struct sockaddr_in *)gw; >>> =C2=A0+ if (gw_sin->sin_len < sizeof(struct sockaddr_in)) { >>> =C2=A0+ printf("gw sin_len too small\n"); >>> =C2=A0+ return (EINVAL); >>> =C2=A0+ } >>> =C2=A0+ fill_sockaddr_inet(gw_sin, gw_sin->sin_addr); >>> =C2=A0+ } >>> =C2=A0+ break; >>> =C2=A0+#endif >>> =C2=A0+#ifdef INET6 >>> =C2=A0+ case AF_INET6: >>> =C2=A0+ { >>> =C2=A0+ struct sockaddr_in6 *gw_sin6 =3D (struct sockaddr_in6 *)gw; >>> =C2=A0+ if (gw_sin6->sin6_len < sizeof(struct sockaddr_in6)) { >>> =C2=A0+ printf("gw sin6_len too small\n"); >>> =C2=A0+ return (EINVAL); >>> =C2=A0+ } >>> =C2=A0+ fill_sockaddr_inet6(gw_sin6, &gw_sin6->sin6_addr, 0); >>> =C2=A0+ break; >>> =C2=A0+ } >>> =C2=A0+#endif >>> =C2=A0+ case AF_LINK: >>> =C2=A0+ { >>> =C2=A0+ struct sockaddr_dl_short *gw_sdl; >>> =C2=A0+ >>> =C2=A0+ gw_sdl =3D (struct sockaddr_dl_short *)gw; >>> =C2=A0+ if (gw_sdl->sdl_len < sizeof(struct sockaddr_dl_short)) { >>> =C2=A0+ printf("gw sdl_len too small\n"); >>> =C2=A0+ return (EINVAL); >>> =C2=A0+ } >>> =C2=A0+ >>> =C2=A0+ const struct sockaddr_dl_short sdl =3D { >>> =C2=A0+ .sdl_family =3D AF_LINK, >>> =C2=A0+ .sdl_len =3D sizeof(struct sockaddr_dl_short), >>> =C2=A0+ .sdl_index =3D gw_sdl->sdl_index, >>> =C2=A0+ }; >>> =C2=A0+ *gw_sdl =3D sdl; >>> =C2=A0+ break; >>> =C2=A0+ } >>> =C2=A0+ } >>> =C2=A0+ >>> =C2=A0+ return (0); >>> =C2=A0+} >>> =C2=A0+ >>> =C2=A0+static int >>> =C2=A0+cleanup_xaddrs_inet(struct rt_addrinfo *info) >>> =C2=A0+{ >>> =C2=A0+ struct sockaddr_in *dst_sa, *mask_sa; >>> =C2=A0+ >>> =C2=A0+ /* Check & fixup dst/netmask combination first */ >>> =C2=A0+ dst_sa =3D (struct sockaddr_in *)info->rti_info[RTAX_DST]; >>> =C2=A0+ mask_sa =3D (struct sockaddr_in *)info->rti_info[RTAX_NETMASK]; >>> =C2=A0+ >>> =C2=A0+ struct in_addr mask =3D { >>> =C2=A0+ .s_addr =3D mask_sa ? mask_sa->sin_addr.s_addr : INADDR_BROADCA= ST, >>> =C2=A0+ }; >>> =C2=A0+ struct in_addr dst =3D { >>> =C2=A0+ .s_addr =3D htonl(ntohl(dst_sa->sin_addr.s_addr) & ntohl(mask.s= _addr)) >>> =C2=A0+ }; >>> =C2=A0+ >>> =C2=A0+ if (dst_sa->sin_len < sizeof(struct sockaddr_in)) { >>> =C2=A0+ printf("dst sin_len too small\n"); >>> =C2=A0+ return (EINVAL); >>> =C2=A0+ } >>> =C2=A0+ if (mask_sa && mask_sa->sin_len < sizeof(struct sockaddr_in)) { >>> =C2=A0+ printf("mask sin_len too small\n"); >>> =C2=A0+ return (EINVAL); >>> =C2=A0+ } >>> =C2=A0+ fill_sockaddr_inet(dst_sa, dst); >>> =C2=A0+ >>> =C2=A0+ if (mask.s_addr !=3D INADDR_BROADCAST) >>> =C2=A0+ fill_sockaddr_inet(mask_sa, mask); >>> =C2=A0+ else { >>> =C2=A0+ info->rti_info[RTAX_NETMASK] =3D NULL; >>> =C2=A0+ info->rti_flags |=3D RTF_HOST; >>> =C2=A0+ info->rti_addrs &=3D ~RTA_NETMASK; >>> =C2=A0+ } >>> =C2=A0+ >>> =C2=A0+ /* Check gateway */ >>> =C2=A0+ if (info->rti_info[RTAX_GATEWAY] !=3D NULL) >>> =C2=A0+ return (cleanup_xaddrs_gateway(info)); >>> =C2=A0+ >>> =C2=A0+ return (0); >>> =C2=A0+} >>> =C2=A0+ >>> =C2=A0+static int >>> =C2=A0+cleanup_xaddrs_inet6(struct rt_addrinfo *info) >>> =C2=A0+{ >>> =C2=A0+ struct sockaddr_in6 *dst_sa, *mask_sa; >>> =C2=A0+ struct in6_addr mask; >>> =C2=A0+ >>> =C2=A0+ /* Check & fixup dst/netmask combination first */ >>> =C2=A0+ dst_sa =3D (struct sockaddr_in6 *)info->rti_info[RTAX_DST]; >>> =C2=A0+ mask_sa =3D (struct sockaddr_in6 *)info->rti_info[RTAX_NETMASK]= ; >>> =C2=A0+ >>> =C2=A0+ mask =3D mask_sa ? mask_sa->sin6_addr : in6mask128; >>> =C2=A0+ IN6_MASK_ADDR(&dst_sa->sin6_addr, &mask); >>> =C2=A0+ >>> =C2=A0+ if (dst_sa->sin6_len < sizeof(struct sockaddr_in6)) { >>> =C2=A0+ printf("dst sin6_len too small\n"); >>> =C2=A0+ return (EINVAL); >>> =C2=A0+ } >>> =C2=A0+ if (mask_sa && mask_sa->sin6_len < sizeof(struct sockaddr_in6))= { >>> =C2=A0+ printf("mask sin6_len too small\n"); >>> =C2=A0+ return (EINVAL); >>> =C2=A0+ } >>> =C2=A0+ fill_sockaddr_inet6(dst_sa, &dst_sa->sin6_addr, 0); >>> =C2=A0+ >>> =C2=A0+ if (!IN6_ARE_ADDR_EQUAL(&mask, &in6mask128)) >>> =C2=A0+ fill_sockaddr_inet6(mask_sa, &mask, 0); >>> =C2=A0+ else { >>> =C2=A0+ info->rti_info[RTAX_NETMASK] =3D NULL; >>> =C2=A0+ info->rti_flags |=3D RTF_HOST; >>> =C2=A0+ info->rti_addrs &=3D ~RTA_NETMASK; >>> =C2=A0+ } >>> =C2=A0+ >>> =C2=A0+ /* Check gateway */ >>> =C2=A0+ if (info->rti_info[RTAX_GATEWAY] !=3D NULL) >>> =C2=A0+ return (cleanup_xaddrs_gateway(info)); >>> =C2=A0+ >>> =C2=A0+ return (0); >>> =C2=A0+} >>> =C2=A0+ >>> =C2=A0+static int >>> =C2=A0+cleanup_xaddrs(struct rt_addrinfo *info) >>> =C2=A0+{ >>> =C2=A0+ int error =3D EAFNOSUPPORT; >>> =C2=A0+ >>> =C2=A0+ if (info->rti_info[RTAX_DST] =3D=3D NULL) >>> =C2=A0+ return (EINVAL); >>> =C2=A0+ >>> =C2=A0+ switch (info->rti_info[RTAX_DST]->sa_family) { >>> =C2=A0+#ifdef INET >>> =C2=A0+ case AF_INET: >>> =C2=A0+ error =3D cleanup_xaddrs_inet(info); >>> =C2=A0+ break; >>> =C2=A0+#endif >>> =C2=A0+#ifdef INET6 >>> =C2=A0+ case AF_INET6: >>> =C2=A0+ error =3D cleanup_xaddrs_inet6(info); >>> =C2=A0+ break; >>> =C2=A0+#endif >>> =C2=A0+ } >>> =C2=A0+ >>> =C2=A0+ return (error); >>> =C2=A0+} >>> =C2=A0+ >>> =C2=A0=C2=A0/* >>> =C2=A0=C2=A0=C2=A0* Fill in @dmask with valid netmask leaving original = @smask >>> =C2=A0=C2=A0=C2=A0* intact. Mostly used with radix netmasks. >>> =C2=A0diff --git a/tests/sys/net/routing/rtsock_common.h >>> =C2=A0b/tests/sys/net/routing/rtsock_common.h >>> =C2=A0index 7da88e0eb512..71476d2b5f3c 100644 >>> =C2=A0--- a/tests/sys/net/routing/rtsock_common.h >>> =C2=A0+++ b/tests/sys/net/routing/rtsock_common.h >>> =C2=A0@@ -826,10 +826,6 @@ _validate_message_sockaddrs(char *buffer, in= t >>> rtm_len, >>> =C2=A0size_t offset, int rtm_ad >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0} >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0sa =3D (struct sockaddr *)((char *)s= a + SA_SIZE(sa)); >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0} >>> =C2=A0- >>> =C2=A0- RTSOCK_ATF_REQUIRE_MSG((struct rt_msghdr *)buffer, parsed_len = =3D=3D >>> rtm_len, >>> =C2=A0- "message len !=3D parsed len: expected %d parsed %d", >>> =C2=A0- rtm_len, (int)parsed_len); >>> =C2=A0=C2=A0} >>> >>> =C2=A0=C2=A0/* >>> =C2=A0_______________________________________________ >>> =C2=A0dev-commits-src-all@freebsd.org mailing list >>> =C2=A0https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all >>> =C2=A0To unsubscribe, send any mail to >>> =C2=A0"dev-commits-src-all-unsubscribe@freebsd.org" >> >> -- >> Mateusz Guzik > --=20 Mateusz Guzik