From e0d7b66f0a3eb9528eebb59b83ce14e8f2025b1d Mon Sep 17 00:00:00 2001 From: Jozsef Kadlecsik Date: Thu, 20 Jan 2011 11:34:00 +0100 Subject: NETMASK*, HOSTMASK* macros are too generic NETMASK*, HOSTMASK* macros are rewritten to small inline functions ip_set_netmask* and ip_set_hostmask* (Patrick McHardy's review) --- kernel/include/linux/netfilter/ipset/pfxlen.h | 31 +++++++++++++++++++++------ kernel/ip_set_bitmap_ip.c | 18 ++++++++-------- kernel/ip_set_bitmap_ipmac.c | 2 +- kernel/ip_set_hash_ip.c | 16 +++++++------- kernel/ip_set_hash_ipport.c | 4 ++-- kernel/ip_set_hash_ipportip.c | 4 ++-- kernel/ip_set_hash_ipportnet.c | 18 ++++++++-------- kernel/ip_set_hash_net.c | 14 ++++++------ kernel/ip_set_hash_netport.c | 14 ++++++------ kernel/pfxlen.c | 8 +++---- 10 files changed, 74 insertions(+), 55 deletions(-) diff --git a/kernel/include/linux/netfilter/ipset/pfxlen.h b/kernel/include/linux/netfilter/ipset/pfxlen.h index fe7153c..08e6059 100644 --- a/kernel/include/linux/netfilter/ipset/pfxlen.h +++ b/kernel/include/linux/netfilter/ipset/pfxlen.h @@ -5,12 +5,31 @@ #include /* Prefixlen maps, by Jan Engelhardt */ -extern const union nf_inet_addr prefixlen_netmask_map[]; -extern const union nf_inet_addr prefixlen_hostmask_map[]; +extern const union nf_inet_addr ip_set_netmask_map[]; +extern const union nf_inet_addr ip_set_hostmask_map[]; -#define NETMASK(n) prefixlen_netmask_map[n].ip -#define NETMASK6(n) prefixlen_netmask_map[n].ip6 -#define HOSTMASK(n) prefixlen_hostmask_map[n].ip -#define HOSTMASK6(n) prefixlen_hostmask_map[n].ip6 +static inline __be32 +ip_set_netmask(u8 pfxlen) +{ + return ip_set_netmask_map[pfxlen].ip; +} + +static inline const __be32 * +ip_set_netmask6(u8 pfxlen) +{ + return &ip_set_netmask_map[pfxlen].ip6[0]; +} + +static inline __be32 +ip_set_hostmask(u8 pfxlen) +{ + return ip_set_hostmask_map[pfxlen].ip; +} + +static inline const __be32 * +ip_set_hostmask6(u8 pfxlen) +{ + return &ip_set_hostmask_map[pfxlen].ip6[0]; +} #endif /*_PFXLEN_H */ diff --git a/kernel/ip_set_bitmap_ip.c b/kernel/ip_set_bitmap_ip.c index a1fed99..fba4f7b 100644 --- a/kernel/ip_set_bitmap_ip.c +++ b/kernel/ip_set_bitmap_ip.c @@ -46,9 +46,9 @@ struct bitmap_ip { }; static inline u32 -ip_to_id(const struct bitmap_ip *map, u32 ip) +ip_to_id(const struct bitmap_ip *m, u32 ip) { - return ((ip & HOSTMASK(map->netmask)) - map->first_ip)/map->hosts; + return ((ip & ip_set_hostmask(m->netmask)) - m->first_ip)/m->hosts; } static inline int @@ -155,8 +155,8 @@ bitmap_ip_uadt(struct ip_set *set, struct nlattr *head, int len, if (cidr > 32) return -IPSET_ERR_INVALID_CIDR; - ip &= HOSTMASK(cidr); - ip_to = ip | ~HOSTMASK(cidr); + ip &= ip_set_hostmask(cidr); + ip_to = ip | ~ip_set_hostmask(cidr); } else ip_to = ip; @@ -391,8 +391,8 @@ bitmap_ip_timeout_uadt(struct ip_set *set, struct nlattr *head, int len, if (cidr > 32) return -IPSET_ERR_INVALID_CIDR; - ip &= HOSTMASK(cidr); - ip_to = ip | ~HOSTMASK(cidr); + ip &= ip_set_hostmask(cidr); + ip_to = ip | ~ip_set_hostmask(cidr); } else ip_to = ip; @@ -623,7 +623,7 @@ bitmap_ip_create(struct ip_set *set, struct nlattr *head, int len, if (cidr >= 32) return -IPSET_ERR_INVALID_CIDR; - last_ip = first_ip | ~HOSTMASK(cidr); + last_ip = first_ip | ~ip_set_hostmask(cidr); } else return -IPSET_ERR_PROTOCOL; @@ -633,8 +633,8 @@ bitmap_ip_create(struct ip_set *set, struct nlattr *head, int len, if (netmask > 32) return -IPSET_ERR_INVALID_NETMASK; - first_ip &= HOSTMASK(netmask); - last_ip |= ~HOSTMASK(netmask); + first_ip &= ip_set_hostmask(netmask); + last_ip |= ~ip_set_hostmask(netmask); } if (netmask == 32) { diff --git a/kernel/ip_set_bitmap_ipmac.c b/kernel/ip_set_bitmap_ipmac.c index a70c601..81f646e 100644 --- a/kernel/ip_set_bitmap_ipmac.c +++ b/kernel/ip_set_bitmap_ipmac.c @@ -594,7 +594,7 @@ bitmap_ipmac_create(struct ip_set *set, struct nlattr *head, int len, if (cidr >= 32) return -IPSET_ERR_INVALID_CIDR; - last_ip = first_ip | ~HOSTMASK(cidr); + last_ip = first_ip | ~ip_set_hostmask(cidr); } else return -IPSET_ERR_PROTOCOL; diff --git a/kernel/ip_set_hash_ip.c b/kernel/ip_set_hash_ip.c index 221abef..7e6af42 100644 --- a/kernel/ip_set_hash_ip.c +++ b/kernel/ip_set_hash_ip.c @@ -126,7 +126,7 @@ hash_ip4_kadt(struct ip_set *set, const struct sk_buff *skb, u32 ip; ip4addrptr(skb, flags & IPSET_DIM_ONE_SRC, &ip); - ip &= NETMASK(h->netmask); + ip &= ip_set_netmask(h->netmask); if (ip == 0) return -EINVAL; @@ -162,7 +162,7 @@ hash_ip4_uadt(struct ip_set *set, struct nlattr *head, int len, if (ret) return ret; - ip &= NETMASK(h->netmask); + ip &= ip_set_netmask(h->netmask); if (ip == 0) return -IPSET_ERR_HASH_ELEM; @@ -188,8 +188,8 @@ hash_ip4_uadt(struct ip_set *set, struct nlattr *head, int len, if (cidr > 32) return -IPSET_ERR_INVALID_CIDR; - ip &= HOSTMASK(cidr); - ip_to = ip | ~HOSTMASK(cidr); + ip &= ip_set_hostmask(cidr); + ip_to = ip | ~ip_set_hostmask(cidr); } else ip_to = ip; @@ -268,10 +268,10 @@ hash_ip6_data_zero_out(struct hash_ip6_elem *elem) static inline void ip6_netmask(union nf_inet_addr *ip, u8 prefix) { - ip->ip6[0] &= NETMASK6(prefix)[0]; - ip->ip6[1] &= NETMASK6(prefix)[1]; - ip->ip6[2] &= NETMASK6(prefix)[2]; - ip->ip6[3] &= NETMASK6(prefix)[3]; + ip->ip6[0] &= ip_set_netmask6(prefix)[0]; + ip->ip6[1] &= ip_set_netmask6(prefix)[1]; + ip->ip6[2] &= ip_set_netmask6(prefix)[2]; + ip->ip6[3] &= ip_set_netmask6(prefix)[3]; } static inline bool diff --git a/kernel/ip_set_hash_ipport.c b/kernel/ip_set_hash_ipport.c index 494619b..035dad1 100644 --- a/kernel/ip_set_hash_ipport.c +++ b/kernel/ip_set_hash_ipport.c @@ -238,8 +238,8 @@ hash_ipport4_uadt(struct ip_set *set, struct nlattr *head, int len, if (cidr > 32) return -IPSET_ERR_INVALID_CIDR; - ip &= HOSTMASK(cidr); - ip_to = ip | ~HOSTMASK(cidr); + ip &= ip_set_hostmask(cidr); + ip_to = ip | ~ip_set_hostmask(cidr); } else ip_to = ip; diff --git a/kernel/ip_set_hash_ipportip.c b/kernel/ip_set_hash_ipportip.c index 0ac31c8..f7a9870 100644 --- a/kernel/ip_set_hash_ipportip.c +++ b/kernel/ip_set_hash_ipportip.c @@ -249,8 +249,8 @@ hash_ipportip4_uadt(struct ip_set *set, struct nlattr *head, int len, if (cidr > 32) return -IPSET_ERR_INVALID_CIDR; - ip &= HOSTMASK(cidr); - ip_to = ip | ~HOSTMASK(cidr); + ip &= ip_set_hostmask(cidr); + ip_to = ip | ~ip_set_hostmask(cidr); } else ip_to = ip; diff --git a/kernel/ip_set_hash_ipportnet.c b/kernel/ip_set_hash_ipportnet.c index 908f580..2200b14 100644 --- a/kernel/ip_set_hash_ipportnet.c +++ b/kernel/ip_set_hash_ipportnet.c @@ -101,7 +101,7 @@ hash_ipportnet4_data_swap(struct hash_ipportnet4_elem *dst, static inline void hash_ipportnet4_data_netmask(struct hash_ipportnet4_elem *elem, u8 cidr) { - elem->ip2 &= NETMASK(cidr); + elem->ip2 &= ip_set_netmask(cidr); elem->cidr = cidr; } @@ -174,7 +174,7 @@ hash_ipportnet4_kadt(struct ip_set *set, const struct sk_buff *skb, ip4addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip); ip4addrptr(skb, flags & IPSET_DIM_THREE_SRC, &data.ip2); - data.ip2 &= NETMASK(data.cidr); + data.ip2 &= ip_set_netmask(data.cidr); return adtfn(set, &data, h->timeout); } @@ -226,7 +226,7 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *head, int len, if (!data.cidr) return -IPSET_ERR_INVALID_CIDR; - data.ip2 &= NETMASK(data.cidr); + data.ip2 &= ip_set_netmask(data.cidr); if (tb[IPSET_ATTR_PORT]) data.port = ip_set_get_n16(tb[IPSET_ATTR_PORT]); @@ -278,8 +278,8 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *head, int len, if (cidr > 32) return -IPSET_ERR_INVALID_CIDR; - ip &= HOSTMASK(cidr); - ip_to = ip | ~HOSTMASK(cidr); + ip &= ip_set_hostmask(cidr); + ip_to = ip | ~ip_set_hostmask(cidr); } else ip_to = ip; @@ -379,10 +379,10 @@ hash_ipportnet6_data_zero_out(struct hash_ipportnet6_elem *elem) static inline void ip6_netmask(union nf_inet_addr *ip, u8 prefix) { - ip->ip6[0] &= NETMASK6(prefix)[0]; - ip->ip6[1] &= NETMASK6(prefix)[1]; - ip->ip6[2] &= NETMASK6(prefix)[2]; - ip->ip6[3] &= NETMASK6(prefix)[3]; + ip->ip6[0] &= ip_set_netmask6(prefix)[0]; + ip->ip6[1] &= ip_set_netmask6(prefix)[1]; + ip->ip6[2] &= ip_set_netmask6(prefix)[2]; + ip->ip6[3] &= ip_set_netmask6(prefix)[3]; } static inline void diff --git a/kernel/ip_set_hash_net.c b/kernel/ip_set_hash_net.c index f2d91a9..693eaf3 100644 --- a/kernel/ip_set_hash_net.c +++ b/kernel/ip_set_hash_net.c @@ -91,7 +91,7 @@ hash_net4_data_swap(struct hash_net4_elem *dst, static inline void hash_net4_data_netmask(struct hash_net4_elem *elem, u8 cidr) { - elem->ip &= NETMASK(cidr); + elem->ip &= ip_set_netmask(cidr); elem->cidr = cidr; } @@ -150,7 +150,7 @@ hash_net4_kadt(struct ip_set *set, const struct sk_buff *skb, data.cidr = HOST_MASK; ip4addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip); - data.ip &= NETMASK(data.cidr); + data.ip &= ip_set_netmask(data.cidr); return adtfn(set, &data, h->timeout); } @@ -189,7 +189,7 @@ hash_net4_uadt(struct ip_set *set, struct nlattr *head, int len, if (!data.cidr) return -IPSET_ERR_INVALID_CIDR; - data.ip &= NETMASK(data.cidr); + data.ip &= ip_set_netmask(data.cidr); if (tb[IPSET_ATTR_TIMEOUT]) { if (!with_timeout(h->timeout)) @@ -271,10 +271,10 @@ hash_net6_data_zero_out(struct hash_net6_elem *elem) static inline void ip6_netmask(union nf_inet_addr *ip, u8 prefix) { - ip->ip6[0] &= NETMASK6(prefix)[0]; - ip->ip6[1] &= NETMASK6(prefix)[1]; - ip->ip6[2] &= NETMASK6(prefix)[2]; - ip->ip6[3] &= NETMASK6(prefix)[3]; + ip->ip6[0] &= ip_set_netmask6(prefix)[0]; + ip->ip6[1] &= ip_set_netmask6(prefix)[1]; + ip->ip6[2] &= ip_set_netmask6(prefix)[2]; + ip->ip6[3] &= ip_set_netmask6(prefix)[3]; } static inline void diff --git a/kernel/ip_set_hash_netport.c b/kernel/ip_set_hash_netport.c index ef06aff..93cc0e8 100644 --- a/kernel/ip_set_hash_netport.c +++ b/kernel/ip_set_hash_netport.c @@ -99,7 +99,7 @@ hash_netport4_data_swap(struct hash_netport4_elem *dst, static inline void hash_netport4_data_netmask(struct hash_netport4_elem *elem, u8 cidr) { - elem->ip &= NETMASK(cidr); + elem->ip &= ip_set_netmask(cidr); elem->cidr = cidr; } @@ -169,7 +169,7 @@ hash_netport4_kadt(struct ip_set *set, const struct sk_buff *skb, return -EINVAL; ip4addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip); - data.ip &= NETMASK(data.cidr); + data.ip &= ip_set_netmask(data.cidr); return adtfn(set, &data, h->timeout); } @@ -212,7 +212,7 @@ hash_netport4_uadt(struct ip_set *set, struct nlattr *head, int len, data.cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]); if (!data.cidr) return -IPSET_ERR_INVALID_CIDR; - data.ip &= NETMASK(data.cidr); + data.ip &= ip_set_netmask(data.cidr); if (tb[IPSET_ATTR_PORT]) data.port = ip_set_get_n16(tb[IPSET_ATTR_PORT]); @@ -338,10 +338,10 @@ hash_netport6_data_zero_out(struct hash_netport6_elem *elem) static inline void ip6_netmask(union nf_inet_addr *ip, u8 prefix) { - ip->ip6[0] &= NETMASK6(prefix)[0]; - ip->ip6[1] &= NETMASK6(prefix)[1]; - ip->ip6[2] &= NETMASK6(prefix)[2]; - ip->ip6[3] &= NETMASK6(prefix)[3]; + ip->ip6[0] &= ip_set_netmask6(prefix)[0]; + ip->ip6[1] &= ip_set_netmask6(prefix)[1]; + ip->ip6[2] &= ip_set_netmask6(prefix)[2]; + ip->ip6[3] &= ip_set_netmask6(prefix)[3]; } static inline void diff --git a/kernel/pfxlen.c b/kernel/pfxlen.c index 5f16b6d..c6c9dcc 100644 --- a/kernel/pfxlen.c +++ b/kernel/pfxlen.c @@ -14,7 +14,7 @@ * This table works for both IPv4 and IPv6; * just use prefixlen_netmask_map[prefixlength].ip. */ -const union nf_inet_addr prefixlen_netmask_map[] = { +const union nf_inet_addr ip_set_netmask_map[] = { E(0x00000000, 0x00000000, 0x00000000, 0x00000000), E(0x80000000, 0x00000000, 0x00000000, 0x00000000), E(0xC0000000, 0x00000000, 0x00000000, 0x00000000), @@ -145,7 +145,7 @@ const union nf_inet_addr prefixlen_netmask_map[] = { E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE), E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF), }; -EXPORT_SYMBOL_GPL(prefixlen_netmask_map); +EXPORT_SYMBOL_GPL(ip_set_netmask_map); #undef E #define E(a, b, c, d) \ @@ -155,7 +155,7 @@ EXPORT_SYMBOL_GPL(prefixlen_netmask_map); * This table works for both IPv4 and IPv6; * just use prefixlen_hostmask_map[prefixlength].ip. */ -const union nf_inet_addr prefixlen_hostmask_map[] = { +const union nf_inet_addr ip_set_hostmask_map[] = { E(0x00000000, 0x00000000, 0x00000000, 0x00000000), E(0x80000000, 0x00000000, 0x00000000, 0x00000000), E(0xC0000000, 0x00000000, 0x00000000, 0x00000000), @@ -286,4 +286,4 @@ const union nf_inet_addr prefixlen_hostmask_map[] = { E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE), E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF), }; -EXPORT_SYMBOL_GPL(prefixlen_hostmask_map); +EXPORT_SYMBOL_GPL(ip_set_hostmask_map); -- cgit v1.2.3