You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.3 KiB

  1. --- a/relay/dhcrelay.c
  2. +++ b/relay/dhcrelay.c
  3. @@ -60,6 +60,7 @@
  4. int client_packet_errors = 0; /* Errors sending packets to clients. */
  5. int add_agent_options = 0; /* If nonzero, add relay agent options. */
  6. +int add_rfc3527_suboption = 0; /* If nonzero, add RFC3527 link selection sub-option. */
  7. int agent_option_errors = 0; /* Number of packets forwarded without
  8. agent options because there was no room. */
  9. @@ -99,6 +100,8 @@
  10. struct sockaddr_in to;
  11. } *servers;
  12. +struct interface_info *uplink;
  13. +
  14. #ifdef DHCPv6
  15. struct stream_list {
  16. struct stream_list *next;
  17. @@ -147,6 +150,7 @@
  18. " [-pf <pid-file>] [--no-pid]\n"\
  19. " [-m append|replace|forward|discard]\n" \
  20. " [-i interface0 [ ... -i interfaceN]\n" \
  21. +" [-l interface]\n" \
  22. " server0 [ ... serverN]\n\n" \
  23. " dhcrelay -6 [-d] [-q] [-I] [-c <hops>] [-p <port>]\n" \
  24. " [-pf <pid-file>] [--no-pid]\n" \
  25. @@ -161,6 +165,7 @@
  26. " [-pf <pid-file>] [--no-pid]\n" \
  27. " [-m append|replace|forward|discard]\n" \
  28. " [-i interface0 [ ... -i interfaceN]\n" \
  29. +" [-l interface]\n" \
  30. " server0 [ ... serverN]\n\n"
  31. #endif
  32. @@ -325,6 +330,20 @@
  33. agent_relay_mode = discard;
  34. } else
  35. usage();
  36. + } else if (!strcmp (argv [i], "-l")) {
  37. + add_agent_options = 1;
  38. + add_rfc3527_suboption = 1;
  39. + if (++i == argc)
  40. + usage();
  41. +
  42. + status = interface_allocate(&uplink, MDL);
  43. + if (status != ISC_R_SUCCESS)
  44. + log_fatal("%s: interface_allocate: %s",
  45. + argv[i],
  46. + isc_result_totext(status));
  47. + strcpy(uplink->name, argv[i]);
  48. + interface_snorf(uplink, INTERFACE_REQUESTED);
  49. + //interface_dereference(&uplink, MDL);
  50. } else if (!strcmp(argv[i], "-D")) {
  51. #ifdef DHCPv6
  52. if (local_family_set && (local_family == AF_INET6)) {
  53. @@ -711,12 +730,17 @@
  54. ip->addresses[0])))
  55. return;
  56. + /* RFC3527: Replace giaddr address by uplink address. The original
  57. + * giaddr will be used in the link selection sub-option */
  58. + if (add_rfc3527_suboption)
  59. + packet->giaddr = uplink->addresses[0];
  60. +
  61. /* If giaddr is not already set, Set it so the server can
  62. figure out what net it's from and so that we can later
  63. forward the response to the correct net. If it's already
  64. set, the response will be sent directly to the relay agent
  65. that set giaddr, so we won't see it. */
  66. - if (!packet->giaddr.s_addr)
  67. + else if (!packet->giaddr.s_addr)
  68. packet->giaddr = ip->addresses[0];
  69. if (packet->hops < max_hop_count)
  70. packet->hops = packet->hops + 1;
  71. @@ -1090,6 +1114,9 @@
  72. optlen += ip->remote_id_len + 2; /* RAI_REMOTE_ID + len */
  73. }
  74. + if (add_rfc3527_suboption)
  75. + optlen += 6;
  76. +
  77. /* We do not support relay option fragmenting(multiple options to
  78. * support an option data exceeding 255 bytes).
  79. */
  80. @@ -1121,6 +1148,14 @@
  81. memcpy(sp, ip->remote_id, ip->remote_id_len);
  82. sp += ip->remote_id_len;
  83. }
  84. +
  85. + if (add_rfc3527_suboption) {
  86. + *sp++ = RAI_LINK_SELECT;
  87. + *sp++ = 4u;
  88. + memcpy(sp, &giaddr.s_addr, 4);
  89. + sp += 4;
  90. + log_debug ("RFC3527 link selection sub-option added: %s", inet_ntoa(giaddr));
  91. + }
  92. } else {
  93. ++agent_option_errors;
  94. log_error("No room in packet (used %d of %d) "