History

bridge: simplify ip_mc_check_igmp() and ipv6_mc_check_mld() calls

This patch refactors ip_mc_check_igmp(), ipv6_mc_check_mld() and their callers (more precisely, the Linux bridge) to not rely on the skb_trimmed parameter anymore. An skb with its tail trimmed to the IP packet length was initially introduced for the following three reasons: 1) To be able to verify the ICMPv6 checksum. 2) To be able to distinguish the version of an IGMP or MLD query. They are distinguishable only by their size. 3) To avoid parsing data for an IGMPv3 or MLDv2 report that is beyond the IP packet but still within the skb. The first case still uses a cloned and potentially trimmed skb to verfiy. However, there is no need to propagate it to the caller. For the second and third case explicit IP packet length checks were added. This hopefully makes ip_mc_check_igmp() and ipv6_mc_check_mld() easier to read and verfiy, as well as easier to use.

Linus Lüssing committed 7 years ago

Commit ba5ea611 parent 6679cf08 files · +70 −72Browse files

Showing the changes to include/linux (3 of 8 files). Show all

Unified · Split

3 files
  1. include/linux/igmp.h +10 −1
  2. include/linux/ip.h +5 −0
  3. include/linux/ipv6.h +6 −0
include/linux/igmp.h+10−1
@@ -18,6 +18,7 @@ · 17 unmodified lines
18#include <linux/skbuff.h>18#include <linux/skbuff.h>
19#include <linux/timer.h>19#include <linux/timer.h>
20#include <linux/in.h>20#include <linux/in.h>
21#include <linux/ip.h>
21#include <linux/refcount.h>22#include <linux/refcount.h>
22#include <uapi/linux/igmp.h>23#include <uapi/linux/igmp.h>
23 24
@@ -106,6 +107,14 @@ struct ip_mc_list { · 82 unmodified lines
106#define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)107#define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
107#define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)108#define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
108 109
110static inline int ip_mc_may_pull(struct sk_buff *skb, unsigned int len)
111{
112 if (skb_transport_offset(skb) + ip_transport_len(skb) < len)
113 return -EINVAL;
114
115 return pskb_may_pull(skb, len);
116}
117
109extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u8 proto);118extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u8 proto);
110extern int igmp_rcv(struct sk_buff *);119extern int igmp_rcv(struct sk_buff *);
111extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);120extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
@@ -130,6 +139,6 @@ extern void ip_mc_unmap(struct in_device *); · 18 unmodified lines
130extern void ip_mc_remap(struct in_device *);139extern void ip_mc_remap(struct in_device *);
131extern void ip_mc_dec_group(struct in_device *in_dev, __be32 addr);140extern void ip_mc_dec_group(struct in_device *in_dev, __be32 addr);
132extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);141extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);
133int ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed);142int ip_mc_check_igmp(struct sk_buff *skb);
134 143
135#endif144#endif
include/linux/ip.h+5−0
@@ -34,4 +34,9 @@ static inline struct iphdr *ipip_hdr(const struct sk_buff *skb) · 33 unmodified lines
34{34{
35 return (struct iphdr *)skb_transport_header(skb);35 return (struct iphdr *)skb_transport_header(skb);
36}36}
37
38static inline unsigned int ip_transport_len(const struct sk_buff *skb)
39{
40 return ntohs(ip_hdr(skb)->tot_len) - skb_network_header_len(skb);
41}
37#endif /* _LINUX_IP_H */42#endif /* _LINUX_IP_H */
include/linux/ipv6.h+6−0
@@ -104,6 +104,12 @@ static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb) · 103 unmodified lines
104 return (struct ipv6hdr *)skb_transport_header(skb);104 return (struct ipv6hdr *)skb_transport_header(skb);
105}105}
106 106
107static inline unsigned int ipv6_transport_len(const struct sk_buff *skb)
108{
109 return ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr) -
110 skb_network_header_len(skb);
111}
112
107/* 113/*
108 This structure contains results of exthdrs parsing114 This structure contains results of exthdrs parsing
109 as offsets from skb->nh.115 as offsets from skb->nh.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t