pfxlen.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. #include <linux/export.h>
  2. #include <linux/netfilter/ipset/pfxlen.h>
  3. /* Prefixlen maps for fast conversions, by Jan Engelhardt. */
  4. #define E(a, b, c, d) \
  5. {.ip6 = { \
  6. htonl(a), htonl(b), \
  7. htonl(c), htonl(d), \
  8. } }
  9. /* This table works for both IPv4 and IPv6;
  10. * just use prefixlen_netmask_map[prefixlength].ip.
  11. */
  12. const union nf_inet_addr ip_set_netmask_map[] = {
  13. E(0x00000000, 0x00000000, 0x00000000, 0x00000000),
  14. E(0x80000000, 0x00000000, 0x00000000, 0x00000000),
  15. E(0xC0000000, 0x00000000, 0x00000000, 0x00000000),
  16. E(0xE0000000, 0x00000000, 0x00000000, 0x00000000),
  17. E(0xF0000000, 0x00000000, 0x00000000, 0x00000000),
  18. E(0xF8000000, 0x00000000, 0x00000000, 0x00000000),
  19. E(0xFC000000, 0x00000000, 0x00000000, 0x00000000),
  20. E(0xFE000000, 0x00000000, 0x00000000, 0x00000000),
  21. E(0xFF000000, 0x00000000, 0x00000000, 0x00000000),
  22. E(0xFF800000, 0x00000000, 0x00000000, 0x00000000),
  23. E(0xFFC00000, 0x00000000, 0x00000000, 0x00000000),
  24. E(0xFFE00000, 0x00000000, 0x00000000, 0x00000000),
  25. E(0xFFF00000, 0x00000000, 0x00000000, 0x00000000),
  26. E(0xFFF80000, 0x00000000, 0x00000000, 0x00000000),
  27. E(0xFFFC0000, 0x00000000, 0x00000000, 0x00000000),
  28. E(0xFFFE0000, 0x00000000, 0x00000000, 0x00000000),
  29. E(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000),
  30. E(0xFFFF8000, 0x00000000, 0x00000000, 0x00000000),
  31. E(0xFFFFC000, 0x00000000, 0x00000000, 0x00000000),
  32. E(0xFFFFE000, 0x00000000, 0x00000000, 0x00000000),
  33. E(0xFFFFF000, 0x00000000, 0x00000000, 0x00000000),
  34. E(0xFFFFF800, 0x00000000, 0x00000000, 0x00000000),
  35. E(0xFFFFFC00, 0x00000000, 0x00000000, 0x00000000),
  36. E(0xFFFFFE00, 0x00000000, 0x00000000, 0x00000000),
  37. E(0xFFFFFF00, 0x00000000, 0x00000000, 0x00000000),
  38. E(0xFFFFFF80, 0x00000000, 0x00000000, 0x00000000),
  39. E(0xFFFFFFC0, 0x00000000, 0x00000000, 0x00000000),
  40. E(0xFFFFFFE0, 0x00000000, 0x00000000, 0x00000000),
  41. E(0xFFFFFFF0, 0x00000000, 0x00000000, 0x00000000),
  42. E(0xFFFFFFF8, 0x00000000, 0x00000000, 0x00000000),
  43. E(0xFFFFFFFC, 0x00000000, 0x00000000, 0x00000000),
  44. E(0xFFFFFFFE, 0x00000000, 0x00000000, 0x00000000),
  45. E(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000),
  46. E(0xFFFFFFFF, 0x80000000, 0x00000000, 0x00000000),
  47. E(0xFFFFFFFF, 0xC0000000, 0x00000000, 0x00000000),
  48. E(0xFFFFFFFF, 0xE0000000, 0x00000000, 0x00000000),
  49. E(0xFFFFFFFF, 0xF0000000, 0x00000000, 0x00000000),
  50. E(0xFFFFFFFF, 0xF8000000, 0x00000000, 0x00000000),
  51. E(0xFFFFFFFF, 0xFC000000, 0x00000000, 0x00000000),
  52. E(0xFFFFFFFF, 0xFE000000, 0x00000000, 0x00000000),
  53. E(0xFFFFFFFF, 0xFF000000, 0x00000000, 0x00000000),
  54. E(0xFFFFFFFF, 0xFF800000, 0x00000000, 0x00000000),
  55. E(0xFFFFFFFF, 0xFFC00000, 0x00000000, 0x00000000),
  56. E(0xFFFFFFFF, 0xFFE00000, 0x00000000, 0x00000000),
  57. E(0xFFFFFFFF, 0xFFF00000, 0x00000000, 0x00000000),
  58. E(0xFFFFFFFF, 0xFFF80000, 0x00000000, 0x00000000),
  59. E(0xFFFFFFFF, 0xFFFC0000, 0x00000000, 0x00000000),
  60. E(0xFFFFFFFF, 0xFFFE0000, 0x00000000, 0x00000000),
  61. E(0xFFFFFFFF, 0xFFFF0000, 0x00000000, 0x00000000),
  62. E(0xFFFFFFFF, 0xFFFF8000, 0x00000000, 0x00000000),
  63. E(0xFFFFFFFF, 0xFFFFC000, 0x00000000, 0x00000000),
  64. E(0xFFFFFFFF, 0xFFFFE000, 0x00000000, 0x00000000),
  65. E(0xFFFFFFFF, 0xFFFFF000, 0x00000000, 0x00000000),
  66. E(0xFFFFFFFF, 0xFFFFF800, 0x00000000, 0x00000000),
  67. E(0xFFFFFFFF, 0xFFFFFC00, 0x00000000, 0x00000000),
  68. E(0xFFFFFFFF, 0xFFFFFE00, 0x00000000, 0x00000000),
  69. E(0xFFFFFFFF, 0xFFFFFF00, 0x00000000, 0x00000000),
  70. E(0xFFFFFFFF, 0xFFFFFF80, 0x00000000, 0x00000000),
  71. E(0xFFFFFFFF, 0xFFFFFFC0, 0x00000000, 0x00000000),
  72. E(0xFFFFFFFF, 0xFFFFFFE0, 0x00000000, 0x00000000),
  73. E(0xFFFFFFFF, 0xFFFFFFF0, 0x00000000, 0x00000000),
  74. E(0xFFFFFFFF, 0xFFFFFFF8, 0x00000000, 0x00000000),
  75. E(0xFFFFFFFF, 0xFFFFFFFC, 0x00000000, 0x00000000),
  76. E(0xFFFFFFFF, 0xFFFFFFFE, 0x00000000, 0x00000000),
  77. E(0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000),
  78. E(0xFFFFFFFF, 0xFFFFFFFF, 0x80000000, 0x00000000),
  79. E(0xFFFFFFFF, 0xFFFFFFFF, 0xC0000000, 0x00000000),
  80. E(0xFFFFFFFF, 0xFFFFFFFF, 0xE0000000, 0x00000000),
  81. E(0xFFFFFFFF, 0xFFFFFFFF, 0xF0000000, 0x00000000),
  82. E(0xFFFFFFFF, 0xFFFFFFFF, 0xF8000000, 0x00000000),
  83. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFC000000, 0x00000000),
  84. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFE000000, 0x00000000),
  85. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFF000000, 0x00000000),
  86. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFF800000, 0x00000000),
  87. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFC00000, 0x00000000),
  88. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFE00000, 0x00000000),
  89. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFF00000, 0x00000000),
  90. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFF80000, 0x00000000),
  91. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFC0000, 0x00000000),
  92. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFE0000, 0x00000000),
  93. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF0000, 0x00000000),
  94. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF8000, 0x00000000),
  95. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFC000, 0x00000000),
  96. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFE000, 0x00000000),
  97. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF000, 0x00000000),
  98. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF800, 0x00000000),
  99. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFC00, 0x00000000),
  100. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFE00, 0x00000000),
  101. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFF00, 0x00000000),
  102. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFF80, 0x00000000),
  103. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC0, 0x00000000),
  104. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE0, 0x00000000),
  105. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF0, 0x00000000),
  106. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF8, 0x00000000),
  107. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFC, 0x00000000),
  108. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE, 0x00000000),
  109. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000),
  110. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x80000000),
  111. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xC0000000),
  112. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xE0000000),
  113. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xF0000000),
  114. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xF8000000),
  115. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFC000000),
  116. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFE000000),
  117. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF000000),
  118. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF800000),
  119. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFC00000),
  120. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFE00000),
  121. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFF00000),
  122. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFF80000),
  123. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFC0000),
  124. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFE0000),
  125. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF0000),
  126. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF8000),
  127. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFC000),
  128. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFE000),
  129. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF000),
  130. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF800),
  131. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFC00),
  132. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFE00),
  133. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFF00),
  134. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFF80),
  135. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC0),
  136. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE0),
  137. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF0),
  138. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF8),
  139. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFC),
  140. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE),
  141. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF),
  142. };
  143. EXPORT_SYMBOL_GPL(ip_set_netmask_map);
  144. #undef E
  145. #define E(a, b, c, d) \
  146. {.ip6 = { (__force __be32)a, (__force __be32)b, \
  147. (__force __be32)c, (__force __be32)d, \
  148. } }
  149. /* This table works for both IPv4 and IPv6;
  150. * just use prefixlen_hostmask_map[prefixlength].ip.
  151. */
  152. const union nf_inet_addr ip_set_hostmask_map[] = {
  153. E(0x00000000, 0x00000000, 0x00000000, 0x00000000),
  154. E(0x80000000, 0x00000000, 0x00000000, 0x00000000),
  155. E(0xC0000000, 0x00000000, 0x00000000, 0x00000000),
  156. E(0xE0000000, 0x00000000, 0x00000000, 0x00000000),
  157. E(0xF0000000, 0x00000000, 0x00000000, 0x00000000),
  158. E(0xF8000000, 0x00000000, 0x00000000, 0x00000000),
  159. E(0xFC000000, 0x00000000, 0x00000000, 0x00000000),
  160. E(0xFE000000, 0x00000000, 0x00000000, 0x00000000),
  161. E(0xFF000000, 0x00000000, 0x00000000, 0x00000000),
  162. E(0xFF800000, 0x00000000, 0x00000000, 0x00000000),
  163. E(0xFFC00000, 0x00000000, 0x00000000, 0x00000000),
  164. E(0xFFE00000, 0x00000000, 0x00000000, 0x00000000),
  165. E(0xFFF00000, 0x00000000, 0x00000000, 0x00000000),
  166. E(0xFFF80000, 0x00000000, 0x00000000, 0x00000000),
  167. E(0xFFFC0000, 0x00000000, 0x00000000, 0x00000000),
  168. E(0xFFFE0000, 0x00000000, 0x00000000, 0x00000000),
  169. E(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000),
  170. E(0xFFFF8000, 0x00000000, 0x00000000, 0x00000000),
  171. E(0xFFFFC000, 0x00000000, 0x00000000, 0x00000000),
  172. E(0xFFFFE000, 0x00000000, 0x00000000, 0x00000000),
  173. E(0xFFFFF000, 0x00000000, 0x00000000, 0x00000000),
  174. E(0xFFFFF800, 0x00000000, 0x00000000, 0x00000000),
  175. E(0xFFFFFC00, 0x00000000, 0x00000000, 0x00000000),
  176. E(0xFFFFFE00, 0x00000000, 0x00000000, 0x00000000),
  177. E(0xFFFFFF00, 0x00000000, 0x00000000, 0x00000000),
  178. E(0xFFFFFF80, 0x00000000, 0x00000000, 0x00000000),
  179. E(0xFFFFFFC0, 0x00000000, 0x00000000, 0x00000000),
  180. E(0xFFFFFFE0, 0x00000000, 0x00000000, 0x00000000),
  181. E(0xFFFFFFF0, 0x00000000, 0x00000000, 0x00000000),
  182. E(0xFFFFFFF8, 0x00000000, 0x00000000, 0x00000000),
  183. E(0xFFFFFFFC, 0x00000000, 0x00000000, 0x00000000),
  184. E(0xFFFFFFFE, 0x00000000, 0x00000000, 0x00000000),
  185. E(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000),
  186. E(0xFFFFFFFF, 0x80000000, 0x00000000, 0x00000000),
  187. E(0xFFFFFFFF, 0xC0000000, 0x00000000, 0x00000000),
  188. E(0xFFFFFFFF, 0xE0000000, 0x00000000, 0x00000000),
  189. E(0xFFFFFFFF, 0xF0000000, 0x00000000, 0x00000000),
  190. E(0xFFFFFFFF, 0xF8000000, 0x00000000, 0x00000000),
  191. E(0xFFFFFFFF, 0xFC000000, 0x00000000, 0x00000000),
  192. E(0xFFFFFFFF, 0xFE000000, 0x00000000, 0x00000000),
  193. E(0xFFFFFFFF, 0xFF000000, 0x00000000, 0x00000000),
  194. E(0xFFFFFFFF, 0xFF800000, 0x00000000, 0x00000000),
  195. E(0xFFFFFFFF, 0xFFC00000, 0x00000000, 0x00000000),
  196. E(0xFFFFFFFF, 0xFFE00000, 0x00000000, 0x00000000),
  197. E(0xFFFFFFFF, 0xFFF00000, 0x00000000, 0x00000000),
  198. E(0xFFFFFFFF, 0xFFF80000, 0x00000000, 0x00000000),
  199. E(0xFFFFFFFF, 0xFFFC0000, 0x00000000, 0x00000000),
  200. E(0xFFFFFFFF, 0xFFFE0000, 0x00000000, 0x00000000),
  201. E(0xFFFFFFFF, 0xFFFF0000, 0x00000000, 0x00000000),
  202. E(0xFFFFFFFF, 0xFFFF8000, 0x00000000, 0x00000000),
  203. E(0xFFFFFFFF, 0xFFFFC000, 0x00000000, 0x00000000),
  204. E(0xFFFFFFFF, 0xFFFFE000, 0x00000000, 0x00000000),
  205. E(0xFFFFFFFF, 0xFFFFF000, 0x00000000, 0x00000000),
  206. E(0xFFFFFFFF, 0xFFFFF800, 0x00000000, 0x00000000),
  207. E(0xFFFFFFFF, 0xFFFFFC00, 0x00000000, 0x00000000),
  208. E(0xFFFFFFFF, 0xFFFFFE00, 0x00000000, 0x00000000),
  209. E(0xFFFFFFFF, 0xFFFFFF00, 0x00000000, 0x00000000),
  210. E(0xFFFFFFFF, 0xFFFFFF80, 0x00000000, 0x00000000),
  211. E(0xFFFFFFFF, 0xFFFFFFC0, 0x00000000, 0x00000000),
  212. E(0xFFFFFFFF, 0xFFFFFFE0, 0x00000000, 0x00000000),
  213. E(0xFFFFFFFF, 0xFFFFFFF0, 0x00000000, 0x00000000),
  214. E(0xFFFFFFFF, 0xFFFFFFF8, 0x00000000, 0x00000000),
  215. E(0xFFFFFFFF, 0xFFFFFFFC, 0x00000000, 0x00000000),
  216. E(0xFFFFFFFF, 0xFFFFFFFE, 0x00000000, 0x00000000),
  217. E(0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000),
  218. E(0xFFFFFFFF, 0xFFFFFFFF, 0x80000000, 0x00000000),
  219. E(0xFFFFFFFF, 0xFFFFFFFF, 0xC0000000, 0x00000000),
  220. E(0xFFFFFFFF, 0xFFFFFFFF, 0xE0000000, 0x00000000),
  221. E(0xFFFFFFFF, 0xFFFFFFFF, 0xF0000000, 0x00000000),
  222. E(0xFFFFFFFF, 0xFFFFFFFF, 0xF8000000, 0x00000000),
  223. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFC000000, 0x00000000),
  224. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFE000000, 0x00000000),
  225. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFF000000, 0x00000000),
  226. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFF800000, 0x00000000),
  227. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFC00000, 0x00000000),
  228. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFE00000, 0x00000000),
  229. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFF00000, 0x00000000),
  230. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFF80000, 0x00000000),
  231. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFC0000, 0x00000000),
  232. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFE0000, 0x00000000),
  233. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF0000, 0x00000000),
  234. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF8000, 0x00000000),
  235. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFC000, 0x00000000),
  236. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFE000, 0x00000000),
  237. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF000, 0x00000000),
  238. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF800, 0x00000000),
  239. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFC00, 0x00000000),
  240. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFE00, 0x00000000),
  241. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFF00, 0x00000000),
  242. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFF80, 0x00000000),
  243. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC0, 0x00000000),
  244. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE0, 0x00000000),
  245. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF0, 0x00000000),
  246. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF8, 0x00000000),
  247. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFC, 0x00000000),
  248. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE, 0x00000000),
  249. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000),
  250. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x80000000),
  251. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xC0000000),
  252. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xE0000000),
  253. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xF0000000),
  254. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xF8000000),
  255. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFC000000),
  256. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFE000000),
  257. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF000000),
  258. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF800000),
  259. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFC00000),
  260. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFE00000),
  261. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFF00000),
  262. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFF80000),
  263. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFC0000),
  264. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFE0000),
  265. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF0000),
  266. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF8000),
  267. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFC000),
  268. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFE000),
  269. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF000),
  270. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF800),
  271. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFC00),
  272. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFE00),
  273. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFF00),
  274. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFF80),
  275. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC0),
  276. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE0),
  277. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF0),
  278. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF8),
  279. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFC),
  280. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE),
  281. E(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF),
  282. };
  283. EXPORT_SYMBOL_GPL(ip_set_hostmask_map);
  284. /* Find the largest network which matches the range from left, in host order. */
  285. u32
  286. ip_set_range_to_cidr(u32 from, u32 to, u8 *cidr)
  287. {
  288. u32 last;
  289. u8 i;
  290. for (i = 1; i < 32; i++) {
  291. if ((from & ip_set_hostmask(i)) != from)
  292. continue;
  293. last = from | ~ip_set_hostmask(i);
  294. if (!after(last, to)) {
  295. *cidr = i;
  296. return last;
  297. }
  298. }
  299. *cidr = 32;
  300. return from;
  301. }
  302. EXPORT_SYMBOL_GPL(ip_set_range_to_cidr);