dhcp-4.2.0-unicast-bootp.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. diff -up dhcp-4.2.0/server/bootp.c.unicast dhcp-4.2.0/server/bootp.c
  2. --- dhcp-4.2.0/server/bootp.c.unicast 2009-11-20 02:49:03.000000000 +0100
  3. +++ dhcp-4.2.0/server/bootp.c 2010-07-21 13:40:25.000000000 +0200
  4. @@ -58,6 +58,7 @@ void bootp (packet)
  5. char msgbuf [1024];
  6. int ignorep;
  7. int peer_has_leases = 0;
  8. + int norelay = 0;
  9. if (packet -> raw -> op != BOOTREQUEST)
  10. return;
  11. @@ -73,7 +74,7 @@ void bootp (packet)
  12. ? inet_ntoa (packet -> raw -> giaddr)
  13. : packet -> interface -> name);
  14. - if (!locate_network (packet)) {
  15. + if ((norelay = locate_network (packet)) == 0) {
  16. log_info ("%s: network unknown", msgbuf);
  17. return;
  18. }
  19. @@ -390,6 +391,13 @@ void bootp (packet)
  20. from, &to, &hto);
  21. goto out;
  22. }
  23. + } else if (norelay == 2) {
  24. + to.sin_addr = raw.ciaddr;
  25. + to.sin_port = remote_port;
  26. + if (fallback_interface) {
  27. + result = send_packet (fallback_interface, (struct packet *)0, &raw, outgoing.packet_length, from, &to, &hto);
  28. + goto out;
  29. + }
  30. /* If it comes from a client that already knows its address
  31. and is not requesting a broadcast response, and we can
  32. diff -up dhcp-4.2.0/server/dhcp.c.unicast dhcp-4.2.0/server/dhcp.c
  33. --- dhcp-4.2.0/server/dhcp.c.unicast 2010-06-01 19:29:59.000000000 +0200
  34. +++ dhcp-4.2.0/server/dhcp.c 2010-07-21 13:40:25.000000000 +0200
  35. @@ -4185,6 +4185,7 @@ int locate_network (packet)
  36. struct data_string data;
  37. struct subnet *subnet = (struct subnet *)0;
  38. struct option_cache *oc;
  39. + int norelay = 0;
  40. /* See if there's a Relay Agent Link Selection Option, or a
  41. * Subnet Selection Option. The Link-Select and Subnet-Select
  42. @@ -4200,12 +4201,24 @@ int locate_network (packet)
  43. from the interface, if there is one. If not, fail. */
  44. if (!oc && !packet -> raw -> giaddr.s_addr) {
  45. if (packet -> interface -> shared_network) {
  46. - shared_network_reference
  47. - (&packet -> shared_network,
  48. - packet -> interface -> shared_network, MDL);
  49. - return 1;
  50. + struct in_addr any_addr;
  51. + any_addr.s_addr = INADDR_ANY;
  52. +
  53. + if (!packet -> packet_type && memcmp(&packet -> raw -> ciaddr, &any_addr, 4)) {
  54. + struct iaddr cip;
  55. + memcpy(cip.iabuf, &packet -> raw -> ciaddr, 4);
  56. + cip.len = 4;
  57. + if (!find_grouped_subnet(&subnet, packet->interface->shared_network, cip, MDL))
  58. + norelay = 2;
  59. + }
  60. +
  61. + if (!norelay) {
  62. + shared_network_reference(&packet -> shared_network, packet -> interface -> shared_network, MDL);
  63. + return 1;
  64. + }
  65. + } else {
  66. + return 0;
  67. }
  68. - return 0;
  69. }
  70. /* If there's an option indicating link connection, and it's valid,
  71. @@ -4228,7 +4241,10 @@ int locate_network (packet)
  72. data_string_forget (&data, MDL);
  73. } else {
  74. ia.len = 4;
  75. - memcpy (ia.iabuf, &packet -> raw -> giaddr, 4);
  76. + if (norelay)
  77. + memcpy (ia.iabuf, &packet->raw->ciaddr, 4);
  78. + else
  79. + memcpy (ia.iabuf, &packet->raw->giaddr, 4);
  80. }
  81. /* If we know the subnet on which the IP address lives, use it. */
  82. @@ -4236,7 +4252,10 @@ int locate_network (packet)
  83. shared_network_reference (&packet -> shared_network,
  84. subnet -> shared_network, MDL);
  85. subnet_dereference (&subnet, MDL);
  86. - return 1;
  87. + if (norelay)
  88. + return norelay;
  89. + else
  90. + return 1;
  91. }
  92. /* Otherwise, fail. */