From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 4E3285A004F for ; Tue, 13 Aug 2024 19:45:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723571120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fBR0tVFx8lcJBqaXI0NflABgPYLoZiXO8gEkoe7c5LA=; b=ehfqtR0bE3j6YQDr/VZb+UAekEKaCXGuNnYFyjV7iGs8qXq5xZo4Ll8segBvUJ1sY6V9Mp K1MQqXjnBq+l286HBHFW92D2dzshMXGhXRdMyM/afrRoVm3lPOAL0SSJdkTsp6jvGTAn9W lItKIdxY2aJ5qXejykl4gTLbf4asWTI= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-446-vkm9XmNlM_aam-ges7xqOQ-1; Tue, 13 Aug 2024 13:45:18 -0400 X-MC-Unique: vkm9XmNlM_aam-ges7xqOQ-1 Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-1fc5e1ab396so59429625ad.2 for ; Tue, 13 Aug 2024 10:45:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723571117; x=1724175917; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=fBR0tVFx8lcJBqaXI0NflABgPYLoZiXO8gEkoe7c5LA=; b=pG/0vOjbMPZjy2MXz2HtplG+qfkugKY5fQx/SWBxU6HQKSjboOVXN97YM6dhZM/t/f RSkxcDyWwf6DxgwngKzPk4L5Rob4TVbuEaLDUw3HDeZtNBAY+fj5kqbx+Wg/C6EmqBT+ bvVvxZ0GJ5Yi40Hewni34y8mCPdMAWiu48VBO2vvVaUw3hiirnhi1Bb0PQZp6TM0JbUu UHJeKeAru5OmTRbyG9wQxSMtGcSHRc6yTijP1DBZl7szOuy3tY9rnaCA9N2rUMFiHgCg kxbK3ZCHaybBx5lLNQc5BSInqzqaIDhyV962wf8Yrw3KHpMTuiU7TlrtI+xya7IK/E9d hSDw== X-Gm-Message-State: AOJu0Yw18FUSfkGBVCrMYFxDjiX1n2J8f93oHt441z4brwhEzwnyYcrV NN2ibRTcM07IrgaHKFZz6vOJ7gIOAyPULe01KExhaQXidVV5aJuYHADV2BtJ1g6sLJnMmrV9/Su vNBf7egjtCoQOI6uwEfnPP/3P2LKvdxdY+LoiiaDjrVOYWD+PPA== X-Received: by 2002:a17:902:e5c8:b0:1fb:57a6:2ae7 with SMTP id d9443c01a7336-201d64d0d1dmr3361155ad.59.1723571116916; Tue, 13 Aug 2024 10:45:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE35zM5zWi2Euai5f5GjlZiFQ62EXiXRexbKqtP5+L1Ado9iA1cAkhVMJ0aKUDr5xBhE6ef9A== X-Received: by 2002:a17:902:e5c8:b0:1fb:57a6:2ae7 with SMTP id d9443c01a7336-201d64d0d1dmr3360935ad.59.1723571116346; Tue, 13 Aug 2024 10:45:16 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201cd1bd2c4sm16282095ad.235.2024.08.13.10.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 10:45:10 -0700 (PDT) Date: Tue, 13 Aug 2024 19:45:07 +0200 From: Stefano Brivio To: AbdAlRahman Gad Subject: Re: [PATCH v2] ndp.c: Turn NDP responder into more declarative implementation Message-ID: <20240813194507.0c8efb97@elisabeth> In-Reply-To: <20240812193338.351810-1-abdobngad@gmail.com> References: <20240812193338.351810-1-abdobngad@gmail.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: NHI4GJ2D63N6EVPLKI54OYHGDV5OSCFK X-Message-ID-Hash: NHI4GJ2D63N6EVPLKI54OYHGDV5OSCFK X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Just two very minor details I'll fix up on merge in a bit (you don't need to send a new version): On Mon, 12 Aug 2024 22:33:38 +0300 AbdAlRahman Gad wrote: > - Add structs for NA, RA, NS, MTU, prefix info, option header, > link-layer address, RDNSS, DNSSL and link-layer for RA message. > > - Turn NA message from purely imperative, going byte by byte, > to declarative by filling it's struct. > > - Turn part of RA message into declarative. > > - Move packet_add() to be before the call of ndp() in tap6_handler() > if the protocol of the packet is ICMPv6. > > - Add a pool of packets as an additional parameter to ndp(). > > - Check the size of NS packet with packet_get() before sending an NA > packet. > > - Add documentation for the structs. > > - Add an enum for NDP option types. > > Link: https://bugs.passt.top/show_bug.cgi?id=21 > > Signed-off-by: AbdAlRahman Gad > --- > ndp.c | 317 ++++++++++++++++++++++++++++++++++++++++++++-------------- > ndp.h | 3 +- > tap.c | 5 +- > 3 files changed, 246 insertions(+), 79 deletions(-) > > diff --git a/ndp.c b/ndp.c > index cea3df5..9a80397 100644 > --- a/ndp.c > +++ b/ndp.c > @@ -38,22 +38,193 @@ > #define NS 135 > #define NA 136 > > +enum ndp_option_types { > + OPT_SRC_L2_ADDR = 1, > + OPT_TARGET_L2_ADDR = 2, > + OPT_PREFIX_INFO = 3, > + OPT_MTU = 5, > + OPT_RDNSS_TYPE = 25, > + OPT_DNSSL_TYPE = 31, > +}; > + > +/** > + * struct opt_header - Option header > + * @type: Option type > + * @len: Option length, in units of 8 bytes > +*/ > +struct opt_header { > + uint8_t type; > + uint8_t len; > +} __attribute__((packed)); > + > +/** > + * struct opt_l2_addr - Link-layer address > + * @header: Option header > + * @mac: MAC address > + */ > +struct opt_l2_addr { > + struct opt_header header; > + unsigned char mac[ETH_ALEN]; > +} __attribute__((packed)); > + > +/** > + * struct ndp_na - NDP Neighbor Advertisement (NA) message > + * @ih: ICMPv6 header > + * @target_addr: Target IPv6 address > + * @target_l2_addr: Target link-layer address > + */ > +struct ndp_na { > + struct icmp6hdr ih; > + struct in6_addr target_addr; > + struct opt_l2_addr target_l2_addr; > +} __attribute__((packed)); > + > +/** > + * struct opt_prefix_info - Prefix Information option > + * @header: Option header > + * @prefix_len: The number of leading bits in the Prefix that are valid > + * @prefix_flags: Flags associated with the prefix > + * @valid_lifetime: Valid lifetime (ms) > + * @pref_lifetime: Preferred lifetime (ms) > + * @reserved: Unused > + */ > +struct opt_prefix_info { > + struct opt_header header; > + uint8_t prefix_len; > + uint8_t prefix_flags; > + uint32_t valid_lifetime; > + uint32_t pref_lifetime; > + uint32_t reserved; > +} __attribute__((packed)); > + > +/** > + * struct mtu_opt - Maximum transmission unit (MTU) option If all the other structs are called opt_*, this should also be opt_mtu, instead of mtu_opt. > + * @header: Option header > + * @reserved: Unused > + * @value: MTU value, network order > + */ > +struct mtu_opt { > + struct opt_header header; > + uint16_t reserved; > + uint32_t value; > +} __attribute__((packed)); > + > +/** > + * struct rdnss - Recursive DNS Server (RDNSS) option > + * @header: Option header > + * @reserved: Unused > + * @lifetime: Validity time (s) > + * @dns: List of DNS server addresses > + */ > +struct opt_rdnss { > + struct opt_header header; > + uint16_t reserved; > + uint32_t lifetime; > + struct in6_addr dns[MAXNS + 1]; > +} __attribute__((packed)); > + > +/** > + * struct dnssl - DNS Search List (DNSSL) option > + * @header: Option header > + * @reserved: Unused > + * @lifetime: Validity time (s) > + * @domains: List of NULL-seperated search domains > + */ > +struct opt_dnssl { > + struct opt_header header; > + uint16_t reserved; > + uint32_t lifetime; > + unsigned char domains[MAXDNSRCH * NS_MAXDNAME]; > +} __attribute__((packed)); > + > +/** > + * struct ndp_ra - NDP Router Advertisement (RA) message > + * @ih: ICMPv6 header > + * @reachable: Reachability time, after confirmation (ms) > + * @retrans: Time between retransmitted NS messages (ms) > + * @prefix_info: Prefix Information option > + * @prefix: IPv6 prefix > + * @mtu: MTU option > + * @source_ll: Target link-layer address > + * @var: Variable fields > + */ > +struct ndp_ra { > + struct icmp6hdr ih; > + uint32_t reachable; > + uint32_t retrans; > + struct opt_prefix_info prefix_info; > + struct in6_addr prefix; > + struct opt_l2_addr source_ll; > + > + unsigned char var[sizeof(struct mtu_opt) +sizeof(struct opt_rdnss) + Missing whitespace before the second sizeof() here. -- Stefano