Skip to content

Commit ca7ce90

Browse files
IVandeVeirecarlescufi
authored andcommitted
net: ip: utils: changed input arguments of igmp_checksum to net_pkt
Added igmpv3 checksum function to make it possible to calculate the checksum of a complete igmpv3 pkt at once. Signed-off-by: Ibe Van de Veire <[email protected]>
1 parent 3ee526b commit ca7ce90

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

subsys/net/ip/Kconfig.ipv4

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ config NET_IPV4_ACCEPT_ZERO_BROADCAST
5050
0.0.0.0 broadcast address as described in RFC 1122 ch. 3.3.6
5151

5252
config NET_IPV4_IGMP
53-
bool "Internet Group Management Protocol (IGMP) support"
53+
bool "Internet Group Management Protocol (IGMPv2) support"
5454
select NET_IPV4_HDR_OPTIONS
5555
help
5656
The value depends on your network needs. IGMP should normally be
@@ -59,6 +59,12 @@ config NET_IPV4_IGMP
5959
because IP Router Alert option must be sent.
6060
See RFC 2236 for details.
6161

62+
config NET_IPV4_IGMPV3
63+
bool "Internet Group Management Protocol version 3 (IGMPv3) support"
64+
depends on NET_IPV4_IGMP
65+
help
66+
Use IGMPv3 for managing the multicast groups.
67+
6268
config NET_DHCPV4
6369
bool "DHCPv4 client"
6470
select NET_MGMT

subsys/net/ip/igmp.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static int igmp_v2_create(struct net_pkt *pkt, const struct in_addr *addr,
5656
igmp->max_rsp = 0U;
5757
net_ipaddr_copy(&igmp->address, addr);
5858
igmp->chksum = 0;
59-
igmp->chksum = net_calc_chksum_igmp((uint8_t *)igmp, sizeof(*igmp));
59+
igmp->chksum = net_calc_chksum_igmp(pkt);
6060

6161
if (net_pkt_set_data(pkt, &igmp_access)) {
6262
return -ENOBUFS;
@@ -217,8 +217,7 @@ enum net_verdict net_ipv4_igmp_input(struct net_pkt *pkt,
217217
return NET_DROP;
218218
}
219219

220-
if (net_calc_chksum_igmp((uint8_t *)igmp_hdr,
221-
sizeof(*igmp_hdr)) != 0U) {
220+
if (net_calc_chksum_igmp(pkt)) {
222221
NET_DBG("DROP: Invalid checksum");
223222
goto drop;
224223
}

subsys/net/ip/net_private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ void net_ipv4_igmp_init(struct net_if *iface);
230230
#endif /* CONFIG_NET_IPV4_IGMP */
231231

232232
#if defined(CONFIG_NET_IPV4_IGMP)
233-
uint16_t net_calc_chksum_igmp(uint8_t *data, size_t len);
233+
uint16_t net_calc_chksum_igmp(struct net_pkt *pkt);
234234
enum net_verdict net_ipv4_igmp_input(struct net_pkt *pkt,
235235
struct net_ipv4_hdr *ip_hdr);
236236
#else
237237
#define net_ipv4_igmp_input(...)
238-
#define net_calc_chksum_igmp(data, len) 0U
238+
#define net_calc_chksum_igmp(struct net_pkt *pkt) 0U
239239
#endif /* CONFIG_NET_IPV4_IGMP */
240240

241241
static inline uint16_t net_calc_chksum_icmpv6(struct net_pkt *pkt)

subsys/net/ip/utils.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ uint16_t net_calc_chksum(struct net_pkt *pkt, uint8_t proto)
644644

645645
if (IS_ENABLED(CONFIG_NET_IPV4) &&
646646
net_pkt_family(pkt) == AF_INET) {
647-
if (proto != IPPROTO_ICMP) {
647+
if (proto != IPPROTO_ICMP && proto != IPPROTO_IGMP) {
648648
len = 2 * sizeof(struct in_addr);
649649
sum = net_pkt_get_len(pkt) -
650650
net_pkt_ip_hdr_len(pkt) -
@@ -700,14 +700,9 @@ uint16_t net_calc_chksum_ipv4(struct net_pkt *pkt)
700700
#endif /* CONFIG_NET_IPV4 */
701701

702702
#if defined(CONFIG_NET_IPV4_IGMP)
703-
uint16_t net_calc_chksum_igmp(uint8_t *data, size_t len)
703+
uint16_t net_calc_chksum_igmp(struct net_pkt *pkt)
704704
{
705-
uint16_t sum;
706-
707-
sum = calc_chksum(0, data, len);
708-
sum = (sum == 0U) ? 0xffff : htons(sum);
709-
710-
return ~sum;
705+
return net_calc_chksum(pkt, IPPROTO_IGMP);
711706
}
712707
#endif /* CONFIG_NET_IPV4_IGMP */
713708

0 commit comments

Comments
 (0)