net: ipv6: mld: refactor query processing into v1/v2 functions
Make igmp6_event_query() a bit easier to read by refactoring code parts into mld_process_v1() and mld_process_v2(). Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Cc: Hannes Frederic Sowa <hannes@stressinduktion.org> Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
cc7f7ab758
commit
2b7c121f82
@@ -1218,6 +1218,55 @@ static void mld_update_qri(struct inet6_dev *idev,
|
|||||||
idev->mc_qri = msecs_to_jiffies(mldv2_mrc(mlh2));
|
idev->mc_qri = msecs_to_jiffies(mldv2_mrc(mlh2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int mld_process_v1(struct inet6_dev *idev, struct mld_msg *mld,
|
||||||
|
unsigned long *max_delay)
|
||||||
|
{
|
||||||
|
unsigned long mldv1_md;
|
||||||
|
|
||||||
|
/* Ignore v1 queries */
|
||||||
|
if (mld_in_v2_mode_only(idev))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
/* MLDv1 router present */
|
||||||
|
mldv1_md = ntohs(mld->mld_maxdelay);
|
||||||
|
*max_delay = max(msecs_to_jiffies(mldv1_md), 1UL);
|
||||||
|
|
||||||
|
mld_set_v1_mode(idev);
|
||||||
|
|
||||||
|
/* cancel MLDv2 report timer */
|
||||||
|
idev->mc_gq_running = 0;
|
||||||
|
if (del_timer(&idev->mc_gq_timer))
|
||||||
|
__in6_dev_put(idev);
|
||||||
|
|
||||||
|
/* cancel the interface change timer */
|
||||||
|
idev->mc_ifc_count = 0;
|
||||||
|
if (del_timer(&idev->mc_ifc_timer))
|
||||||
|
__in6_dev_put(idev);
|
||||||
|
|
||||||
|
/* clear deleted report items */
|
||||||
|
mld_clear_delrec(idev);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mld_process_v2(struct inet6_dev *idev, struct mld2_query *mld,
|
||||||
|
unsigned long *max_delay)
|
||||||
|
{
|
||||||
|
/* hosts need to stay in MLDv1 mode, discard MLDv2 queries */
|
||||||
|
if (mld_in_v1_mode(idev))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
*max_delay = max(msecs_to_jiffies(mldv2_mrc(mld)), 1UL);
|
||||||
|
|
||||||
|
mld_update_qrv(idev, mld);
|
||||||
|
mld_update_qi(idev, mld);
|
||||||
|
mld_update_qri(idev, mld);
|
||||||
|
|
||||||
|
idev->mc_maxdelay = *max_delay;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* called with rcu_read_lock() */
|
/* called with rcu_read_lock() */
|
||||||
int igmp6_event_query(struct sk_buff *skb)
|
int igmp6_event_query(struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
@@ -1229,7 +1278,7 @@ int igmp6_event_query(struct sk_buff *skb)
|
|||||||
struct mld_msg *mld;
|
struct mld_msg *mld;
|
||||||
int group_type;
|
int group_type;
|
||||||
int mark = 0;
|
int mark = 0;
|
||||||
int len;
|
int len, err;
|
||||||
|
|
||||||
if (!pskb_may_pull(skb, sizeof(struct in6_addr)))
|
if (!pskb_may_pull(skb, sizeof(struct in6_addr)))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -1255,47 +1304,21 @@ int igmp6_event_query(struct sk_buff *skb)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (len == MLD_V1_QUERY_LEN) {
|
if (len == MLD_V1_QUERY_LEN) {
|
||||||
unsigned long mldv1_md;
|
err = mld_process_v1(idev, mld, &max_delay);
|
||||||
|
if (err < 0)
|
||||||
/* Ignore v1 queries */
|
return err;
|
||||||
if (mld_in_v2_mode_only(idev))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* MLDv1 router present */
|
|
||||||
mldv1_md = ntohs(mld->mld_maxdelay);
|
|
||||||
max_delay = max(msecs_to_jiffies(mldv1_md), 1UL);
|
|
||||||
|
|
||||||
mld_set_v1_mode(idev);
|
|
||||||
|
|
||||||
/* cancel MLDv2 report timer */
|
|
||||||
idev->mc_gq_running = 0;
|
|
||||||
if (del_timer(&idev->mc_gq_timer))
|
|
||||||
__in6_dev_put(idev);
|
|
||||||
|
|
||||||
/* cancel the interface change timer */
|
|
||||||
idev->mc_ifc_count = 0;
|
|
||||||
if (del_timer(&idev->mc_ifc_timer))
|
|
||||||
__in6_dev_put(idev);
|
|
||||||
/* clear deleted report items */
|
|
||||||
mld_clear_delrec(idev);
|
|
||||||
} else if (len >= MLD_V2_QUERY_LEN_MIN) {
|
} else if (len >= MLD_V2_QUERY_LEN_MIN) {
|
||||||
int srcs_offset = sizeof(struct mld2_query) -
|
int srcs_offset = sizeof(struct mld2_query) -
|
||||||
sizeof(struct icmp6hdr);
|
sizeof(struct icmp6hdr);
|
||||||
|
|
||||||
/* hosts need to stay in MLDv1 mode, discard MLDv2 queries */
|
|
||||||
if (mld_in_v1_mode(idev))
|
|
||||||
return 0;
|
|
||||||
if (!pskb_may_pull(skb, srcs_offset))
|
if (!pskb_may_pull(skb, srcs_offset))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
mlh2 = (struct mld2_query *)skb_transport_header(skb);
|
mlh2 = (struct mld2_query *)skb_transport_header(skb);
|
||||||
|
|
||||||
max_delay = max(msecs_to_jiffies(mldv2_mrc(mlh2)), 1UL);
|
err = mld_process_v2(idev, mlh2, &max_delay);
|
||||||
idev->mc_maxdelay = max_delay;
|
if (err < 0)
|
||||||
|
return err;
|
||||||
mld_update_qrv(idev, mlh2);
|
|
||||||
mld_update_qi(idev, mlh2);
|
|
||||||
mld_update_qri(idev, mlh2);
|
|
||||||
|
|
||||||
if (group_type == IPV6_ADDR_ANY) { /* general query */
|
if (group_type == IPV6_ADDR_ANY) { /* general query */
|
||||||
if (mlh2->mld2q_nsrcs)
|
if (mlh2->mld2q_nsrcs)
|
||||||
|
Reference in New Issue
Block a user