Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _PFXLEN_H
0003 #define _PFXLEN_H
0004 
0005 #include <asm/byteorder.h>
0006 #include <linux/netfilter.h>
0007 #include <net/tcp.h>
0008 
0009 /* Prefixlen maps, by Jan Engelhardt  */
0010 extern const union nf_inet_addr ip_set_netmask_map[];
0011 extern const union nf_inet_addr ip_set_hostmask_map[];
0012 
0013 static inline __be32
0014 ip_set_netmask(u8 pfxlen)
0015 {
0016     return ip_set_netmask_map[pfxlen].ip;
0017 }
0018 
0019 static inline const __be32 *
0020 ip_set_netmask6(u8 pfxlen)
0021 {
0022     return &ip_set_netmask_map[pfxlen].ip6[0];
0023 }
0024 
0025 static inline u32
0026 ip_set_hostmask(u8 pfxlen)
0027 {
0028     return (__force u32) ip_set_hostmask_map[pfxlen].ip;
0029 }
0030 
0031 static inline const __be32 *
0032 ip_set_hostmask6(u8 pfxlen)
0033 {
0034     return &ip_set_hostmask_map[pfxlen].ip6[0];
0035 }
0036 
0037 extern u32 ip_set_range_to_cidr(u32 from, u32 to, u8 *cidr);
0038 
0039 #define ip_set_mask_from_to(from, to, cidr) \
0040 do {                        \
0041     from &= ip_set_hostmask(cidr);      \
0042     to = from | ~ip_set_hostmask(cidr); \
0043 } while (0)
0044 
0045 static inline void
0046 ip6_netmask(union nf_inet_addr *ip, u8 prefix)
0047 {
0048     ip->ip6[0] &= ip_set_netmask6(prefix)[0];
0049     ip->ip6[1] &= ip_set_netmask6(prefix)[1];
0050     ip->ip6[2] &= ip_set_netmask6(prefix)[2];
0051     ip->ip6[3] &= ip_set_netmask6(prefix)[3];
0052 }
0053 
0054 #endif /*_PFXLEN_H */