14_cidr_support 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. diff -ruN tcp_wrappers_7.6.orig/hosts_access.5 tcp_wrappers_7.6/hosts_access.5
  2. --- tcp_wrappers_7.6.orig/hosts_access.5 2003-08-21 03:15:36.000000000 +0200
  3. +++ tcp_wrappers_7.6/hosts_access.5 2003-08-21 03:15:31.000000000 +0200
  4. @@ -90,6 +90,10 @@
  5. pattern `131.155.72.0/255.255.254.0\' matches every address in the
  6. range `131.155.72.0\' through `131.155.73.255\'.
  7. .IP \(bu
  8. +An expression of the form `n.n.n.n/mm' is interpreted as a
  9. +`net/masklength' pair, where `mm' is the number of consecutive `1'
  10. +bits in the netmask applied to the `n.n.n.n' address.
  11. +.IP \(bu
  12. An expression of the form `[n:n:n:n:n:n:n:n]/m\' is interpreted as a
  13. `[net]/prefixlen\' pair. An IPv6 host address is matched if
  14. `prefixlen\' bits of `net\' is equal to the `prefixlen\' bits of the
  15. diff -ruN tcp_wrappers_7.6.orig/hosts_access.c tcp_wrappers_7.6/hosts_access.c
  16. --- tcp_wrappers_7.6.orig/hosts_access.c 2003-08-21 03:15:36.000000000 +0200
  17. +++ tcp_wrappers_7.6/hosts_access.c 2003-08-21 03:09:30.000000000 +0200
  18. @@ -417,7 +417,8 @@
  19. if ((addr = dot_quad_addr(string)) == INADDR_NONE)
  20. return (NO);
  21. if ((net = dot_quad_addr(net_tok)) == INADDR_NONE
  22. - || (mask = dot_quad_addr(mask_tok)) == INADDR_NONE) {
  23. + || ((mask = dot_quad_addr(mask_tok)) == INADDR_NONE
  24. + && (mask = cidr_mask_addr(mask_tok)) == 0)) {
  25. #ifndef INET6
  26. tcpd_warn("bad net/mask expression: %s/%s", net_tok, mask_tok);
  27. #endif
  28. diff -ruN tcp_wrappers_7.6.orig/misc.c tcp_wrappers_7.6/misc.c
  29. --- tcp_wrappers_7.6.orig/misc.c 2003-08-21 03:15:36.000000000 +0200
  30. +++ tcp_wrappers_7.6/misc.c 2003-08-21 03:09:30.000000000 +0200
  31. @@ -107,3 +107,17 @@
  32. }
  33. return (runs == 4 ? inet_addr(str) : INADDR_NONE);
  34. }
  35. +
  36. +/* cidr_mask_addr - convert cidr netmask length to internal form */
  37. +
  38. +unsigned long cidr_mask_addr(str)
  39. +char *str;
  40. +{
  41. + int maskbits;
  42. +
  43. + maskbits = atoi(str);
  44. + if (maskbits < 1 || maskbits > 32)
  45. + return (0);
  46. + return htonl(0xFFFFFFFF << (32 - maskbits));
  47. +}
  48. +
  49. diff -ruN tcp_wrappers_7.6.orig/tcpdchk.c tcp_wrappers_7.6/tcpdchk.c
  50. --- tcp_wrappers_7.6.orig/tcpdchk.c 2003-08-21 03:15:36.000000000 +0200
  51. +++ tcp_wrappers_7.6/tcpdchk.c 2003-08-21 03:09:30.000000000 +0200
  52. @@ -497,12 +497,12 @@
  53. int mask_len;
  54. if ((dot_quad_addr(pat) == INADDR_NONE
  55. - || dot_quad_addr(mask) == INADDR_NONE)
  56. + || dot_quad_addr(mask) == INADDR_NONE && cidr_mask_addr(mask) == 0)
  57. && (!is_inet6_addr(pat)
  58. || ((mask_len = atoi(mask)) < 0 || mask_len > 128)))
  59. #else
  60. if (dot_quad_addr(pat) == INADDR_NONE
  61. - || dot_quad_addr(mask) == INADDR_NONE)
  62. + || dot_quad_addr(mask) == INADDR_NONE && cidr_mask_addr(mask) == 0)
  63. #endif
  64. tcpd_warn("%s/%s: bad net/mask pattern", pat, mask);
  65. } else if (STR_EQ(pat, "FAIL")) { /* obsolete */