Commit bbc318f6 authored by David S. Miller's avatar David S. Miller

Merge branch 'bridge-mrd'

Linus Lüssing says:

====================
bridge: implement Multicast Router Discovery (RFC4286)

This patchset adds initial Multicast Router Discovery support to
the Linux bridge (RFC4286). With MRD it is possible to detect multicast
routers and mark bridge ports and forward multicast packets to such routers
accordingly.

So far, multicast routers are detected via IGMP/MLD queries and PIM
messages in the Linux bridge. As there is only one active, selected
querier at a time RFC4541 ("Considerations for Internet Group Management
Protocol (IGMP) and Multicast Listener Discovery (MLD) Snooping
Switches") section 2.1.1.a) recommends snooping Multicast Router
Advertisements as provided by MRD (RFC4286).

The first two patches are refactoring some existing code which is reused
for parsing the Multicast Router Advertisements later in the fourth
patch. The third patch lets the bridge join the all-snoopers multicast
address to be able to reliably receive the Multicast Router
Advertisements.

What is not implemented yet from RFC4286 yet:

* Sending Multicast Router Solicitations:
  -> RFC4286: "[...] may be sent when [...] an interface is
     (re-)initialized [or] MRD is enabled"
* Snooping Multicast Router Terminations:
  -> currently this only relies on our own timeouts
* Adjusting timeouts with the values provided in the announcements

Changes in v2:

* rebased to current net-next/master (no conflicts/changes)
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 6679cf09 4b3087c7
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/in.h> #include <linux/in.h>
#include <linux/ip.h>
#include <linux/refcount.h> #include <linux/refcount.h>
#include <uapi/linux/igmp.h> #include <uapi/linux/igmp.h>
...@@ -106,6 +107,14 @@ struct ip_mc_list { ...@@ -106,6 +107,14 @@ struct ip_mc_list {
#define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value) #define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
#define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value) #define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
static inline int ip_mc_may_pull(struct sk_buff *skb, unsigned int len)
{
if (skb_transport_offset(skb) + ip_transport_len(skb) < len)
return -EINVAL;
return pskb_may_pull(skb, len);
}
extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u8 proto); extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u8 proto);
extern int igmp_rcv(struct sk_buff *); extern int igmp_rcv(struct sk_buff *);
extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr); extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
...@@ -130,6 +139,6 @@ extern void ip_mc_unmap(struct in_device *); ...@@ -130,6 +139,6 @@ extern void ip_mc_unmap(struct in_device *);
extern void ip_mc_remap(struct in_device *); extern void ip_mc_remap(struct in_device *);
extern void ip_mc_dec_group(struct in_device *in_dev, __be32 addr); extern void ip_mc_dec_group(struct in_device *in_dev, __be32 addr);
extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr); extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);
int ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed); int ip_mc_check_igmp(struct sk_buff *skb);
#endif #endif
...@@ -60,6 +60,11 @@ static inline bool ipv4_is_lbcast(__be32 addr) ...@@ -60,6 +60,11 @@ static inline bool ipv4_is_lbcast(__be32 addr)
return addr == htonl(INADDR_BROADCAST); return addr == htonl(INADDR_BROADCAST);
} }
static inline bool ipv4_is_all_snoopers(__be32 addr)
{
return addr == htonl(INADDR_ALLSNOOPERS_GROUP);
}
static inline bool ipv4_is_zeronet(__be32 addr) static inline bool ipv4_is_zeronet(__be32 addr)
{ {
return (addr & htonl(0xff000000)) == htonl(0x00000000); return (addr & htonl(0xff000000)) == htonl(0x00000000);
......
...@@ -34,4 +34,9 @@ static inline struct iphdr *ipip_hdr(const struct sk_buff *skb) ...@@ -34,4 +34,9 @@ static inline struct iphdr *ipip_hdr(const struct sk_buff *skb)
{ {
return (struct iphdr *)skb_transport_header(skb); return (struct iphdr *)skb_transport_header(skb);
} }
static inline unsigned int ip_transport_len(const struct sk_buff *skb)
{
return ntohs(ip_hdr(skb)->tot_len) - skb_network_header_len(skb);
}
#endif /* _LINUX_IP_H */ #endif /* _LINUX_IP_H */
...@@ -104,6 +104,12 @@ static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb) ...@@ -104,6 +104,12 @@ static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb)
return (struct ipv6hdr *)skb_transport_header(skb); return (struct ipv6hdr *)skb_transport_header(skb);
} }
static inline unsigned int ipv6_transport_len(const struct sk_buff *skb)
{
return ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr) -
skb_network_header_len(skb);
}
/* /*
This structure contains results of exthdrs parsing This structure contains results of exthdrs parsing
as offsets from skb->nh. as offsets from skb->nh.
......
...@@ -49,6 +49,7 @@ struct prefix_info { ...@@ -49,6 +49,7 @@ struct prefix_info {
struct in6_addr prefix; struct in6_addr prefix;
}; };
#include <linux/ipv6.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <net/if_inet6.h> #include <net/if_inet6.h>
#include <net/ipv6.h> #include <net/ipv6.h>
...@@ -201,6 +202,15 @@ u32 ipv6_addr_label(struct net *net, const struct in6_addr *addr, ...@@ -201,6 +202,15 @@ u32 ipv6_addr_label(struct net *net, const struct in6_addr *addr,
/* /*
* multicast prototypes (mcast.c) * multicast prototypes (mcast.c)
*/ */
static inline int ipv6_mc_may_pull(struct sk_buff *skb,
unsigned int len)
{
if (skb_transport_offset(skb) + ipv6_transport_len(skb) < len)
return -EINVAL;
return pskb_may_pull(skb, len);
}
int ipv6_sock_mc_join(struct sock *sk, int ifindex, int ipv6_sock_mc_join(struct sock *sk, int ifindex,
const struct in6_addr *addr); const struct in6_addr *addr);
int ipv6_sock_mc_drop(struct sock *sk, int ifindex, int ipv6_sock_mc_drop(struct sock *sk, int ifindex,
...@@ -219,7 +229,8 @@ void ipv6_mc_unmap(struct inet6_dev *idev); ...@@ -219,7 +229,8 @@ void ipv6_mc_unmap(struct inet6_dev *idev);
void ipv6_mc_remap(struct inet6_dev *idev); void ipv6_mc_remap(struct inet6_dev *idev);
void ipv6_mc_init_dev(struct inet6_dev *idev); void ipv6_mc_init_dev(struct inet6_dev *idev);
void ipv6_mc_destroy_dev(struct inet6_dev *idev); void ipv6_mc_destroy_dev(struct inet6_dev *idev);
int ipv6_mc_check_mld(struct sk_buff *skb, struct sk_buff **skb_trimmed); int ipv6_mc_check_icmpv6(struct sk_buff *skb);
int ipv6_mc_check_mld(struct sk_buff *skb);
void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp); void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp);
bool ipv6_chk_mcast_addr(struct net_device *dev, const struct in6_addr *group, bool ipv6_chk_mcast_addr(struct net_device *dev, const struct in6_addr *group,
...@@ -489,6 +500,20 @@ static inline bool ipv6_addr_is_solict_mult(const struct in6_addr *addr) ...@@ -489,6 +500,20 @@ static inline bool ipv6_addr_is_solict_mult(const struct in6_addr *addr)
#endif #endif
} }
static inline bool ipv6_addr_is_all_snoopers(const struct in6_addr *addr)
{
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
__be64 *p = (__be64 *)addr;
return ((p[0] ^ cpu_to_be64(0xff02000000000000UL)) |
(p[1] ^ cpu_to_be64(0x6a))) == 0UL;
#else
return ((addr->s6_addr32[0] ^ htonl(0xff020000)) |
addr->s6_addr32[1] | addr->s6_addr32[2] |
(addr->s6_addr32[3] ^ htonl(0x0000006a))) == 0;
#endif
}
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
int if6_proc_init(void); int if6_proc_init(void);
void if6_proc_exit(void); void if6_proc_exit(void);
......
...@@ -108,6 +108,8 @@ struct icmp6hdr { ...@@ -108,6 +108,8 @@ struct icmp6hdr {
#define ICMPV6_MOBILE_PREFIX_SOL 146 #define ICMPV6_MOBILE_PREFIX_SOL 146
#define ICMPV6_MOBILE_PREFIX_ADV 147 #define ICMPV6_MOBILE_PREFIX_ADV 147
#define ICMPV6_MRDISC_ADV 151
/* /*
* Codes for Destination Unreachable * Codes for Destination Unreachable
*/ */
......
...@@ -93,6 +93,7 @@ struct igmpv3_query { ...@@ -93,6 +93,7 @@ struct igmpv3_query {
#define IGMP_MTRACE_RESP 0x1e #define IGMP_MTRACE_RESP 0x1e
#define IGMP_MTRACE 0x1f #define IGMP_MTRACE 0x1f
#define IGMP_MRDISC_ADV 0x30 /* From RFC4286 */
/* /*
* Use the BSD names for these for compatibility * Use the BSD names for these for compatibility
......
...@@ -292,10 +292,11 @@ struct sockaddr_in { ...@@ -292,10 +292,11 @@ struct sockaddr_in {
#define IN_LOOPBACK(a) ((((long int) (a)) & 0xff000000) == 0x7f000000) #define IN_LOOPBACK(a) ((((long int) (a)) & 0xff000000) == 0x7f000000)
/* Defines for Multicast INADDR */ /* Defines for Multicast INADDR */
#define INADDR_UNSPEC_GROUP 0xe0000000U /* 224.0.0.0 */ #define INADDR_UNSPEC_GROUP 0xe0000000U /* 224.0.0.0 */
#define INADDR_ALLHOSTS_GROUP 0xe0000001U /* 224.0.0.1 */ #define INADDR_ALLHOSTS_GROUP 0xe0000001U /* 224.0.0.1 */
#define INADDR_ALLRTRS_GROUP 0xe0000002U /* 224.0.0.2 */ #define INADDR_ALLRTRS_GROUP 0xe0000002U /* 224.0.0.2 */
#define INADDR_MAX_LOCAL_GROUP 0xe00000ffU /* 224.0.0.255 */ #define INADDR_ALLSNOOPERS_GROUP 0xe000006aU /* 224.0.0.106 */
#define INADDR_MAX_LOCAL_GROUP 0xe00000ffU /* 224.0.0.255 */
#endif #endif
/* <asm/byteorder.h> contains the htonl type stuff.. */ /* <asm/byteorder.h> contains the htonl type stuff.. */
......
...@@ -674,7 +674,7 @@ static void batadv_mcast_mla_update(struct work_struct *work) ...@@ -674,7 +674,7 @@ static void batadv_mcast_mla_update(struct work_struct *work)
*/ */
static bool batadv_mcast_is_report_ipv4(struct sk_buff *skb) static bool batadv_mcast_is_report_ipv4(struct sk_buff *skb)
{ {
if (ip_mc_check_igmp(skb, NULL) < 0) if (ip_mc_check_igmp(skb) < 0)
return false; return false;
switch (igmp_hdr(skb)->type) { switch (igmp_hdr(skb)->type) {
...@@ -741,7 +741,7 @@ static int batadv_mcast_forw_mode_check_ipv4(struct batadv_priv *bat_priv, ...@@ -741,7 +741,7 @@ static int batadv_mcast_forw_mode_check_ipv4(struct batadv_priv *bat_priv,
*/ */
static bool batadv_mcast_is_report_ipv6(struct sk_buff *skb) static bool batadv_mcast_is_report_ipv6(struct sk_buff *skb)
{ {
if (ipv6_mc_check_mld(skb, NULL) < 0) if (ipv6_mc_check_mld(skb) < 0)
return false; return false;
switch (icmp6_hdr(skb)->icmp6_type) { switch (icmp6_hdr(skb)->icmp6_type) {
......
This diff is collapsed.
...@@ -1493,22 +1493,22 @@ static int ip_mc_check_igmp_reportv3(struct sk_buff *skb) ...@@ -1493,22 +1493,22 @@ static int ip_mc_check_igmp_reportv3(struct sk_buff *skb)
len += sizeof(struct igmpv3_report); len += sizeof(struct igmpv3_report);
return pskb_may_pull(skb, len) ? 0 : -EINVAL; return ip_mc_may_pull(skb, len) ? 0 : -EINVAL;
} }
static int ip_mc_check_igmp_query(struct sk_buff *skb) static int ip_mc_check_igmp_query(struct sk_buff *skb)
{ {
unsigned int len = skb_transport_offset(skb); unsigned int transport_len = ip_transport_len(skb);
unsigned int len;
len += sizeof(struct igmphdr);
if (skb->len < len)
return -EINVAL;
/* IGMPv{1,2}? */ /* IGMPv{1,2}? */
if (skb->len != len) { if (transport_len != sizeof(struct igmphdr)) {
/* or IGMPv3? */ /* or IGMPv3? */
len += sizeof(struct igmpv3_query) - sizeof(struct igmphdr); if (transport_len < sizeof(struct igmpv3_query))
if (skb->len < len || !pskb_may_pull(skb, len)) return -EINVAL;
len = skb_transport_offset(skb) + sizeof(struct igmpv3_query);
if (!ip_mc_may_pull(skb, len))
return -EINVAL; return -EINVAL;
} }
...@@ -1544,47 +1544,29 @@ static inline __sum16 ip_mc_validate_checksum(struct sk_buff *skb) ...@@ -1544,47 +1544,29 @@ static inline __sum16 ip_mc_validate_checksum(struct sk_buff *skb)
return skb_checksum_simple_validate(skb); return skb_checksum_simple_validate(skb);
} }
static int __ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed) static int ip_mc_check_igmp_csum(struct sk_buff *skb)
{ {
struct sk_buff *skb_chk;
unsigned int transport_len;
unsigned int len = skb_transport_offset(skb) + sizeof(struct igmphdr); unsigned int len = skb_transport_offset(skb) + sizeof(struct igmphdr);
int ret = -EINVAL; unsigned int transport_len = ip_transport_len(skb);
struct sk_buff *skb_chk;
transport_len = ntohs(ip_hdr(skb)->tot_len) - ip_hdrlen(skb); if (!ip_mc_may_pull(skb, len))
return -EINVAL;
skb_chk = skb_checksum_trimmed(skb, transport_len, skb_chk = skb_checksum_trimmed(skb, transport_len,
ip_mc_validate_checksum); ip_mc_validate_checksum);
if (!skb_chk) if (!skb_chk)
goto err; return -EINVAL;
if (!pskb_may_pull(skb_chk, len))
goto err;
ret = ip_mc_check_igmp_msg(skb_chk);
if (ret)
goto err;
if (skb_trimmed)
*skb_trimmed = skb_chk;
/* free now unneeded clone */
else if (skb_chk != skb)
kfree_skb(skb_chk);
ret = 0;
err: if (skb_chk != skb)
if (ret && skb_chk && skb_chk != skb)
kfree_skb(skb_chk); kfree_skb(skb_chk);
return ret; return 0;
} }
/** /**
* ip_mc_check_igmp - checks whether this is a sane IGMP packet * ip_mc_check_igmp - checks whether this is a sane IGMP packet
* @skb: the skb to validate * @skb: the skb to validate
* @skb_trimmed: to store an skb pointer trimmed to IPv4 packet tail (optional)
* *
* Checks whether an IPv4 packet is a valid IGMP packet. If so sets * Checks whether an IPv4 packet is a valid IGMP packet. If so sets
* skb transport header accordingly and returns zero. * skb transport header accordingly and returns zero.
...@@ -1594,18 +1576,10 @@ static int __ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed) ...@@ -1594,18 +1576,10 @@ static int __ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed)
* -ENOMSG: IP header validation succeeded but it is not an IGMP packet. * -ENOMSG: IP header validation succeeded but it is not an IGMP packet.
* -ENOMEM: A memory allocation failure happened. * -ENOMEM: A memory allocation failure happened.
* *
* Optionally, an skb pointer might be provided via skb_trimmed (or set it
* to NULL): After parsing an IGMP packet successfully it will point to
* an skb which has its tail aligned to the IP packet end. This might
* either be the originally provided skb or a trimmed, cloned version if
* the skb frame had data beyond the IP packet. A cloned skb allows us
* to leave the original skb and its full frame unchanged (which might be
* desirable for layer 2 frame jugglers).
*
* Caller needs to set the skb network header and free any returned skb if it * Caller needs to set the skb network header and free any returned skb if it
* differs from the provided skb. * differs from the provided skb.
*/ */
int ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed) int ip_mc_check_igmp(struct sk_buff *skb)
{ {
int ret = ip_mc_check_iphdr(skb); int ret = ip_mc_check_iphdr(skb);
...@@ -1615,7 +1589,11 @@ int ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed) ...@@ -1615,7 +1589,11 @@ int ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed)
if (ip_hdr(skb)->protocol != IPPROTO_IGMP) if (ip_hdr(skb)->protocol != IPPROTO_IGMP)
return -ENOMSG; return -ENOMSG;
return __ip_mc_check_igmp(skb, skb_trimmed); ret = ip_mc_check_igmp_csum(skb);
if (ret < 0)
return ret;
return ip_mc_check_igmp_msg(skb);
} }
EXPORT_SYMBOL(ip_mc_check_igmp); EXPORT_SYMBOL(ip_mc_check_igmp);
......
...@@ -940,6 +940,7 @@ int ipv6_dev_mc_inc(struct net_device *dev, const struct in6_addr *addr) ...@@ -940,6 +940,7 @@ int ipv6_dev_mc_inc(struct net_device *dev, const struct in6_addr *addr)
{ {
return __ipv6_dev_mc_inc(dev, addr, MCAST_EXCLUDE); return __ipv6_dev_mc_inc(dev, addr, MCAST_EXCLUDE);
} }
EXPORT_SYMBOL(ipv6_dev_mc_inc);
/* /*
* device multicast group del * device multicast group del
...@@ -987,6 +988,7 @@ int ipv6_dev_mc_dec(struct net_device *dev, const struct in6_addr *addr) ...@@ -987,6 +988,7 @@ int ipv6_dev_mc_dec(struct net_device *dev, const struct in6_addr *addr)
return err; return err;
} }
EXPORT_SYMBOL(ipv6_dev_mc_dec);
/* /*
* check if the interface/address pair is valid * check if the interface/address pair is valid
......
...@@ -41,6 +41,8 @@ static int ipv6_mc_check_ip6hdr(struct sk_buff *skb) ...@@ -41,6 +41,8 @@ static int ipv6_mc_check_ip6hdr(struct sk_buff *skb)
if (skb->len < len || len <= offset) if (skb->len < len || len <= offset)
return -EINVAL; return -EINVAL;
skb_set_transport_header(skb, offset);
return 0; return 0;
} }
...@@ -77,27 +79,27 @@ static int ipv6_mc_check_mld_reportv2(struct sk_buff *skb) ...@@ -77,27 +79,27 @@ static int ipv6_mc_check_mld_reportv2(struct sk_buff *skb)
len += sizeof(struct mld2_report); len += sizeof(struct mld2_report);
return pskb_may_pull(skb, len) ? 0 : -EINVAL; return ipv6_mc_may_pull(skb, len) ? 0 : -EINVAL;
} }
static int ipv6_mc_check_mld_query(struct sk_buff *skb) static int ipv6_mc_check_mld_query(struct sk_buff *skb)
{ {
unsigned int transport_len = ipv6_transport_len(skb);
struct mld_msg *mld; struct mld_msg *mld;
unsigned int len = skb_transport_offset(skb); unsigned int len;
/* RFC2710+RFC3810 (MLDv1+MLDv2) require link-local source addresses */ /* RFC2710+RFC3810 (MLDv1+MLDv2) require link-local source addresses */
if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL)) if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL))
return -EINVAL; return -EINVAL;
len += sizeof(struct mld_msg);
if (skb->len < len)
return -EINVAL;
/* MLDv1? */ /* MLDv1? */
if (skb->len != len) { if (transport_len != sizeof(struct mld_msg)) {
/* or MLDv2? */ /* or MLDv2? */
len += sizeof(struct mld2_query) - sizeof(struct mld_msg); if (transport_len < sizeof(struct mld2_query))
if (skb->len < len || !pskb_may_pull(skb, len)) return -EINVAL;
len = skb_transport_offset(skb) + sizeof(struct mld2_query);
if (!ipv6_mc_may_pull(skb, len))
return -EINVAL; return -EINVAL;
} }
...@@ -115,7 +117,13 @@ static int ipv6_mc_check_mld_query(struct sk_buff *skb) ...@@ -115,7 +117,13 @@ static int ipv6_mc_check_mld_query(struct sk_buff *skb)
static int ipv6_mc_check_mld_msg(struct sk_buff *skb) static int ipv6_mc_check_mld_msg(struct sk_buff *skb)
{ {
struct mld_msg *mld = (struct mld_msg *)skb_transport_header(skb); unsigned int len = skb_transport_offset(skb) + sizeof(struct mld_msg);
struct mld_msg *mld;
if (!ipv6_mc_may_pull(skb, len))
return -EINVAL;
mld = (struct mld_msg *)skb_transport_header(skb);
switch (mld->mld_type) { switch (mld->mld_type) {
case ICMPV6_MGM_REDUCTION: case ICMPV6_MGM_REDUCTION:
...@@ -136,49 +144,30 @@ static inline __sum16 ipv6_mc_validate_checksum(struct sk_buff *skb) ...@@ -136,49 +144,30 @@ static inline __sum16 ipv6_mc_validate_checksum(struct sk_buff *skb)
return skb_checksum_validate(skb, IPPROTO_ICMPV6, ip6_compute_pseudo); return skb_checksum_validate(skb, IPPROTO_ICMPV6, ip6_compute_pseudo);
} }
static int __ipv6_mc_check_mld(struct sk_buff *skb, int ipv6_mc_check_icmpv6(struct sk_buff *skb)
struct sk_buff **skb_trimmed)
{ {
struct sk_buff *skb_chk = NULL; unsigned int len = skb_transport_offset(skb) + sizeof(struct icmp6hdr);
unsigned int transport_len; unsigned int transport_len = ipv6_transport_len(skb);
unsigned int len = skb_transport_offset(skb) + sizeof(struct mld_msg); struct sk_buff *skb_chk;
int ret = -EINVAL;
transport_len = ntohs(ipv6_hdr(skb)->payload_len); if (!ipv6_mc_may_pull(skb, len))
transport_len -= skb_transport_offset(skb) - sizeof(struct ipv6hdr); return -EINVAL;
skb_chk = skb_checksum_trimmed(skb, transport_len, skb_chk = skb_checksum_trimmed(skb, transport_len,
ipv6_mc_validate_checksum); ipv6_mc_validate_checksum);
if (!skb_chk) if (!skb_chk)
goto err; return -EINVAL;
if (!pskb_may_pull(skb_chk, len))
goto err;
ret = ipv6_mc_check_mld_msg(skb_chk);
if (ret)
goto err;
if (skb_trimmed)
*skb_trimmed = skb_chk;
/* free now unneeded clone */
else if (skb_chk != skb)
kfree_skb(skb_chk);
ret = 0;
err: if (skb_chk != skb)
if (ret && skb_chk && skb_chk != skb)
kfree_skb(skb_chk); kfree_skb(skb_chk);
return ret; return 0;
} }
EXPORT_SYMBOL(ipv6_mc_check_icmpv6);
/** /**
* ipv6_mc_check_mld - checks whether this is a sane MLD packet * ipv6_mc_check_mld - checks whether this is a sane MLD packet
* @skb: the skb to validate * @skb: the skb to validate
* @skb_trimmed: to store an skb pointer trimmed to IPv6 packet tail (optional)
* *
* Checks whether an IPv6 packet is a valid MLD packet. If so sets * Checks whether an IPv6 packet is a valid MLD packet. If so sets
* skb transport header accordingly and returns zero. * skb transport header accordingly and returns zero.
...@@ -188,18 +177,10 @@ static int __ipv6_mc_check_mld(struct sk_buff *skb, ...@@ -188,18 +177,10 @@ static int __ipv6_mc_check_mld(struct sk_buff *skb,
* -ENOMSG: IP header validation succeeded but it is not an MLD packet. * -ENOMSG: IP header validation succeeded but it is not an MLD packet.
* -ENOMEM: A memory allocation failure happened. * -ENOMEM: A memory allocation failure happened.
* *
* Optionally, an skb pointer might be provided via skb_trimmed (or set it
* to NULL): After parsing an MLD packet successfully it will point to
* an skb which has its tail aligned to the IP packet end. This might
* either be the originally provided skb or a trimmed, cloned version if
* the skb frame had data beyond the IP packet. A cloned skb allows us
* to leave the original skb and its full frame unchanged (which might be
* desirable for layer 2 frame jugglers).
*
* Caller needs to set the skb network header and free any returned skb if it * Caller needs to set the skb network header and free any returned skb if it
* differs from the provided skb. * differs from the provided skb.
*/ */
int ipv6_mc_check_mld(struct sk_buff *skb, struct sk_buff **skb_trimmed) int ipv6_mc_check_mld(struct sk_buff *skb)
{ {
int ret; int ret;
...@@ -211,6 +192,10 @@ int ipv6_mc_check_mld(struct sk_buff *skb, struct sk_buff **skb_trimmed) ...@@ -211,6 +192,10 @@ int ipv6_mc_check_mld(struct sk_buff *skb, struct sk_buff **skb_trimmed)
if (ret < 0) if (ret < 0)
return ret; return ret;
return __ipv6_mc_check_mld(skb, skb_trimmed); ret = ipv6_mc_check_icmpv6(skb);
if (ret < 0)
return ret;
return ipv6_mc_check_mld_msg(skb);
} }
EXPORT_SYMBOL(ipv6_mc_check_mld); EXPORT_SYMBOL(ipv6_mc_check_mld);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment