|
| 1 | +From 1d59a7bd4dc9cb3cd13aedf604a15a8589febe43 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Joe LeVeque < [email protected]> |
| 3 | +Date: Thu, 2 May 2019 19:46:42 +0000 |
| 4 | +Subject: [PATCH 2/2] Port upstream changes from commit |
| 5 | + edd6d8881bc4d8ec4b04173c66c1c840756bbe76 to add '-id' option |
| 6 | + |
| 7 | +--- |
| 8 | + relay/dhcrelay.c | 89 +++++++++++++++++++++++++++++++++--------------- |
| 9 | + 1 file changed, 61 insertions(+), 28 deletions(-) |
| 10 | + |
| 11 | +diff --git a/relay/dhcrelay.c b/relay/dhcrelay.c |
| 12 | +index 8051e17..292ba4f 100644 |
| 13 | +--- a/relay/dhcrelay.c |
| 14 | ++++ b/relay/dhcrelay.c |
| 15 | +@@ -142,6 +142,8 @@ static int strip_relay_agent_options(struct interface_info *, |
| 16 | + struct interface_info **, |
| 17 | + struct dhcp_packet *, unsigned); |
| 18 | + |
| 19 | ++static void request_v4_interface(const char* name, int flags); |
| 20 | ++ |
| 21 | + static int load_interface_alias_map(const char *port_alias_map_file_path); |
| 22 | + static int get_interface_alias_by_name(const char *if_name, char *if_alias_out); |
| 23 | + static void free_interface_alias_map(void); |
| 24 | +@@ -173,6 +175,7 @@ static const char url[] = |
| 25 | + " [--name-alias-map-file <name-alias-map-file>]\n" \ |
| 26 | + " [-i interface0 [ ... -i interfaceN]\n" \ |
| 27 | + " [-iu interface0 [ ... -iu interfaceN]\n" \ |
| 28 | ++" [-id interface0 [ ... -id interfaceN]\n" \ |
| 29 | + " server0 [ ... serverN]\n\n" \ |
| 30 | + " dhcrelay -6 [-d] [-q] [-I] [-c <hops>] [-p <port>]\n" \ |
| 31 | + " [-pf <pid-file>] [--no-pid]\n" \ |
| 32 | +@@ -190,6 +193,7 @@ static const char url[] = |
| 33 | + " [-m append|replace|forward|discard]\n" \ |
| 34 | + " [-i interface0 [ ... -i interfaceN]\n" \ |
| 35 | + " [-iu interface0 [ ... -iu interfaceN]\n" \ |
| 36 | ++" [-id interface0 [ ... -id interfaceN]\n" \ |
| 37 | + " server0 [ ... serverN]\n\n" DHCRELAY_OPTION82_USAGE |
| 38 | + #endif |
| 39 | + |
| 40 | +@@ -294,21 +298,8 @@ main(int argc, char **argv) { |
| 41 | + if (++i == argc) { |
| 42 | + usage(); |
| 43 | + } |
| 44 | +- if (strlen(argv[i]) >= sizeof(tmp->name)) { |
| 45 | +- log_fatal("%s: interface name too long " |
| 46 | +- "(is %ld)", |
| 47 | +- argv[i], (long)strlen(argv[i])); |
| 48 | +- } |
| 49 | +- status = interface_allocate(&tmp, MDL); |
| 50 | +- if (status != ISC_R_SUCCESS) { |
| 51 | +- log_fatal("%s: interface_allocate: %s", |
| 52 | +- argv[i], |
| 53 | +- isc_result_totext(status)); |
| 54 | +- } |
| 55 | +- strcpy(tmp->name, argv[i]); |
| 56 | +- interface_snorf(tmp, (INTERFACE_REQUESTED | |
| 57 | +- INTERFACE_STREAMS)); |
| 58 | +- interface_dereference(&tmp, MDL); |
| 59 | ++ |
| 60 | ++ request_v4_interface(argv[i], INTERFACE_STREAMS); |
| 61 | + } else if (!strcmp(argv[i], "-iu")) { |
| 62 | + #ifdef DHCPv6 |
| 63 | + if (local_family_set && (local_family == AF_INET6)) { |
| 64 | +@@ -320,21 +311,21 @@ main(int argc, char **argv) { |
| 65 | + if (++i == argc) { |
| 66 | + usage(); |
| 67 | + } |
| 68 | +- if (strlen(argv[i]) >= sizeof(tmp->name)) { |
| 69 | +- log_fatal("%s: interface name too long " |
| 70 | +- "(is %ld)", |
| 71 | +- argv[i], (long)strlen(argv[i])); |
| 72 | ++ |
| 73 | ++ request_v4_interface(argv[i], INTERFACE_UPSTREAM); |
| 74 | ++ } else if (!strcmp(argv[i], "-id")) { |
| 75 | ++#ifdef DHCPv6 |
| 76 | ++ if (local_family_set && (local_family == AF_INET6)) { |
| 77 | ++ usage(); |
| 78 | + } |
| 79 | +- status = interface_allocate(&tmp, MDL); |
| 80 | +- if (status != ISC_R_SUCCESS) { |
| 81 | +- log_fatal("%s: interface_allocate: %s", |
| 82 | +- argv[i], |
| 83 | +- isc_result_totext(status)); |
| 84 | ++ local_family_set = 1; |
| 85 | ++ local_family = AF_INET; |
| 86 | ++#endif |
| 87 | ++ if (++i == argc) { |
| 88 | ++ usage(); |
| 89 | + } |
| 90 | +- strcpy(tmp->name, argv[i]); |
| 91 | +- interface_snorf(tmp, (INTERFACE_REQUESTED | |
| 92 | +- INTERFACE_UPSTREAM)); |
| 93 | +- interface_dereference(&tmp, MDL); |
| 94 | ++ |
| 95 | ++ request_v4_interface(argv[i], INTERFACE_DOWNSTREAM); |
| 96 | + } else if (!strcmp(argv[i], "-a")) { |
| 97 | + #ifdef DHCPv6 |
| 98 | + if (local_family_set && (local_family == AF_INET6)) { |
| 99 | +@@ -782,6 +773,11 @@ do_relay4(struct interface_info *ip, struct dhcp_packet *packet, |
| 100 | + if (out) |
| 101 | + return; |
| 102 | + |
| 103 | ++ if (!(ip->flags & INTERFACE_DOWNSTREAM)) { |
| 104 | ++ log_debug("Dropping request received on %s", ip->name); |
| 105 | ++ return; |
| 106 | ++ } |
| 107 | ++ |
| 108 | + /* Add relay agent options if indicated. If something goes wrong, |
| 109 | + drop the packet. */ |
| 110 | + if (!(length = add_relay_agent_options(ip, packet, length, |
| 111 | +@@ -1991,6 +1987,43 @@ dhcp_set_control_state(control_object_state_t oldstate, |
| 112 | + exit(0); |
| 113 | + } |
| 114 | + |
| 115 | ++/*! |
| 116 | ++ * |
| 117 | ++ * \brief Allocate an interface as requested with a given set of flags |
| 118 | ++ * |
| 119 | ++ * The requested interface is allocated, its flags field is set to |
| 120 | ++ * INTERFACE_REQUESTED OR'd with the given flags, and then added to |
| 121 | ++ * the list of interfaces. |
| 122 | ++ * |
| 123 | ++ * \param name - name of the requested interface |
| 124 | ++ * \param flags - additional flags for the interface |
| 125 | ++ * |
| 126 | ++ * \return Nothing |
| 127 | ++ */ |
| 128 | ++void request_v4_interface(const char* name, int flags) { |
| 129 | ++ struct interface_info *tmp = NULL; |
| 130 | ++ int len = strlen(name); |
| 131 | ++ isc_result_t status; |
| 132 | ++ |
| 133 | ++ if (len >= sizeof(tmp->name)) { |
| 134 | ++ log_fatal("%s: interface name too long (is %d)", name, len); |
| 135 | ++ } |
| 136 | ++ |
| 137 | ++ status = interface_allocate(&tmp, MDL); |
| 138 | ++ if (status != ISC_R_SUCCESS) { |
| 139 | ++ log_fatal("%s: interface_allocate: %s", name, |
| 140 | ++ isc_result_totext(status)); |
| 141 | ++ } |
| 142 | ++ |
| 143 | ++ log_debug("Requesting: %s as upstream: %c downstream: %c", name, |
| 144 | ++ (flags & INTERFACE_UPSTREAM ? 'Y' : 'N'), |
| 145 | ++ (flags & INTERFACE_DOWNSTREAM ? 'Y' : 'N')); |
| 146 | ++ |
| 147 | ++ strncpy(tmp->name, name, len); |
| 148 | ++ interface_snorf(tmp, (INTERFACE_REQUESTED | flags)); |
| 149 | ++ interface_dereference(&tmp, MDL); |
| 150 | ++} |
| 151 | ++ |
| 152 | + #define MAX_PORT_CONFIG_LINE_LEN 1024 |
| 153 | + |
| 154 | + // Allocates and loads global map g_interface_name_alias_map |
| 155 | +-- |
| 156 | +2.17.1 |
| 157 | + |
0 commit comments