History

netfilter: ebtables: add support for matching IGMP type

We already have ICMPv6 type/code matches (which can be used to distinguish different types of MLD packets). Add support for IPv4 IGMP matches in the same way.

Matthias Schiffer committed 8 years ago

Commit 78d9f4d1 parent 5adc1662 files · +20 −3Browse files

Unified · Split

2 files
  1. include/uapi/linux/netfilter_bridge/ebt_ip.h +3 −1
  2. net/bridge/netfilter/ebt_ip.c +17 −2
include/uapi/linux/netfilter_bridge/ebt_ip.h+3−1
@@ -25,8 +25,9 @@ · 24 unmodified lines
2525 #define EBT_IP_SPORT 0x10
2626 #define EBT_IP_DPORT 0x20
2727 #define EBT_IP_ICMP 0x40
28+#define EBT_IP_IGMP 0x80
2829 #define EBT_IP_MASK (EBT_IP_SOURCE | EBT_IP_DEST | EBT_IP_TOS | EBT_IP_PROTO |\
29− EBT_IP_SPORT | EBT_IP_DPORT | EBT_IP_ICMP)
30+ EBT_IP_SPORT | EBT_IP_DPORT | EBT_IP_ICMP | EBT_IP_IGMP)
3031 #define EBT_IP_MATCH "ip"
3132
3233 /* the same values are used for the invflags */
@@ -42,6 +43,7 @@ struct ebt_ip_info { · 9 unmodified lines
4243 union {
4344 __u16 sport[2];
4445 __u8 icmp_type[2];
46+ __u8 igmp_type[2];
4547 };
4648 union {
4749 __u16 dport[2];
net/bridge/netfilter/ebt_ip.c+17−2
@@ -28,6 +28,9 @@ union pkthdr { · 27 unmodified lines
2828 u8 type;
2929 u8 code;
3030 } icmphdr;
31+ struct {
32+ u8 type;
33+ } igmphdr;
3134 };
3235
3336 static bool
@@ -57,12 +60,12 @@ ebt_ip_mt(const struct sk_buff *skb, struct xt_action_param *par) · 23 unmodified lines
5760 if (NF_INVF(info, EBT_IP_PROTO, info->protocol != ih->protocol))
5861 return false;
5962 if (!(info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT |
60− EBT_IP_ICMP)))
63+ EBT_IP_ICMP | EBT_IP_IGMP)))
6164 return true;
6265 if (ntohs(ih->frag_off) & IP_OFFSET)
6366 return false;
6467
65− /* min icmp headersize is 4, so sizeof(_pkthdr) is ok. */
68+ /* min icmp/igmp headersize is 4, so sizeof(_pkthdr) is ok. */
6669 pptr = skb_header_pointer(skb, ih->ihl*4,
6770 sizeof(_pkthdr), &_pkthdr);
6871 if (pptr == NULL)
@@ -88,6 +91,11 @@ ebt_ip_mt(const struct sk_buff *skb, struct xt_action_param *par) · 19 unmodified lines
8891 pptr->icmphdr.code < info->icmp_code[0] ||
8992 pptr->icmphdr.code > info->icmp_code[1]))
9093 return false;
94+ if ((info->bitmask & EBT_IP_IGMP) &&
95+ NF_INVF(info, EBT_IP_IGMP,
96+ pptr->igmphdr.type < info->igmp_type[0] ||
97+ pptr->igmphdr.type > info->igmp_type[1]))
98+ return false;
9199 }
92100 return true;
93101 }
@@ -124,6 +132,13 @@ static int ebt_ip_mt_check(const struct xt_mtchk_param *par) · 30 unmodified lines
124132 info->icmp_code[0] > info->icmp_code[1])
125133 return -EINVAL;
126134 }
135+ if (info->bitmask & EBT_IP_IGMP) {
136+ if ((info->invflags & EBT_IP_PROTO) ||
137+ info->protocol != IPPROTO_IGMP)
138+ return -EINVAL;
139+ if (info->igmp_type[0] > info->igmp_type[1])
140+ return -EINVAL;
141+ }
127142 return 0;
128143 }
129144