FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
dhcp4_proxy_node.c
Go to the documentation of this file.
1 /*
2  * proxy_node.c: dhcp proxy node processing
3  *
4  * Copyright (c) 2013 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vlib/vlib.h>
19 #include <vnet/pg/pg.h>
20 #include <vnet/dhcp/dhcp_proxy.h>
21 #include <vnet/dhcp/client.h>
22 #include <vnet/fib/ip4_fib.h>
23 
24 static char *dhcp_proxy_error_strings[] = {
25 #define dhcp_proxy_error(n,s) s,
27 #undef dhcp_proxy_error
28 };
29 
30 #define foreach_dhcp_proxy_to_server_input_next \
31  _ (DROP, "error-drop") \
32  _ (LOOKUP, "ip4-lookup") \
33  _ (SEND_TO_CLIENT, "dhcp-proxy-to-client")
34 
35 typedef enum
36 {
37 #define _(s,n) DHCP_PROXY_TO_SERVER_INPUT_NEXT_##s,
39 #undef _
42 
43 typedef struct
44 {
45  /* 0 => to server, 1 => to client */
46  int which;
52 
53 #define VPP_DHCP_OPTION82_SUB1_SIZE 6
54 #define VPP_DHCP_OPTION82_SUB5_SIZE 6
55 #define VPP_DHCP_OPTION82_VSS_SIZE 12
56 #define VPP_DHCP_OPTION82_SIZE (VPP_DHCP_OPTION82_SUB1_SIZE + \
57  VPP_DHCP_OPTION82_SUB5_SIZE + \
58  VPP_DHCP_OPTION82_VSS_SIZE +3)
59 
62 
63 static u8 *
64 format_dhcp_proxy_trace (u8 * s, va_list * args)
65 {
66  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
67  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
68  dhcp_proxy_trace_t *t = va_arg (*args, dhcp_proxy_trace_t *);
69 
70  if (t->which == 0)
71  s = format (s, "DHCP proxy: sent to server %U\n",
73  else
74  s = format (s, "DHCP proxy: broadcast to client from %U\n",
76 
77  if (t->error != (u32) ~ 0)
78  s = format (s, " error: %s\n", dhcp_proxy_error_strings[t->error]);
79 
80  s = format (s, " original_sw_if_index: %d, sw_if_index: %d\n",
82 
83  return s;
84 }
85 
86 static u8 *
88 {
89  dhcp_header_t *h = va_arg (*args, dhcp_header_t *);
90  u32 max_header_bytes = va_arg (*args, u32);
91  u32 header_bytes;
92 
93  header_bytes = sizeof (h[0]);
94  if (max_header_bytes != 0 && header_bytes > max_header_bytes)
95  return format (s, "dhcp header truncated");
96 
97  s = format (s, "DHCP Proxy");
98 
99  return s;
100 }
101 
102 static uword
104  vlib_node_runtime_t * node,
105  vlib_frame_t * from_frame)
106 {
107  u32 n_left_from, next_index, *from, *to_next;
109  from = vlib_frame_vector_args (from_frame);
110  n_left_from = from_frame->n_vectors;
111  u32 pkts_to_server = 0, pkts_to_client = 0, pkts_no_server = 0;
112  u32 pkts_no_interface_address = 0;
113  u32 pkts_too_big = 0;
114  ip4_main_t *im = &ip4_main;
115 
116  next_index = node->cached_next_index;
117 
118  while (n_left_from > 0)
119  {
120  u32 n_left_to_next;
121 
122  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
123 
124  while (n_left_from > 0 && n_left_to_next > 0)
125  {
126  u32 bi0;
127  vlib_buffer_t *b0;
128  udp_header_t *u0;
129  dhcp_header_t *h0;
130  ip4_header_t *ip0;
131  u32 next0;
132  u32 old0, new0;
133  ip_csum_t sum0;
134  u32 error0 = (u32) ~ 0;
135  u32 sw_if_index = 0;
136  u32 original_sw_if_index = 0;
137  u32 fib_index;
138  dhcp_proxy_t *proxy;
139  dhcp_server_t *server;
140  u32 rx_sw_if_index;
141  dhcp_option_t *o, *end;
142  u32 len = 0;
143  u8 is_discover = 0;
144  int space_left;
145 
146  bi0 = from[0];
147  from += 1;
148  n_left_from -= 1;
149 
150  b0 = vlib_get_buffer (vm, bi0);
151 
152  h0 = vlib_buffer_get_current (b0);
153 
154  /*
155  * udp_local hands us the DHCP header, need udp hdr,
156  * ip hdr to relay to server
157  */
158  vlib_buffer_advance (b0, -(sizeof (*u0)));
159  u0 = vlib_buffer_get_current (b0);
160 
161  /* This blows. Return traffic has src_port = 67, dst_port = 67 */
162  if (u0->src_port ==
163  clib_net_to_host_u16 (UDP_DST_PORT_dhcp_to_server))
164  {
165  vlib_buffer_advance (b0, sizeof (*u0));
166  next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_SEND_TO_CLIENT;
167  error0 = 0;
168  pkts_to_client++;
169  goto do_enqueue;
170  }
171 
172  rx_sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
173  fib_index = im->fib_index_by_sw_if_index[rx_sw_if_index];
174  proxy = dhcp_get_proxy (dpm, fib_index, FIB_PROTOCOL_IP4);
175 
176  if (PREDICT_FALSE (NULL == proxy))
177  {
178  error0 = DHCP_PROXY_ERROR_NO_SERVER;
179  next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
180  pkts_no_server++;
181  goto do_trace;
182  }
183 
184  if (!vlib_buffer_chain_linearize (vm, b0))
185  {
186  error0 = DHCP_PROXY_ERROR_PKT_TOO_BIG;
187  next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
188  pkts_too_big++;
189  goto do_trace;
190  }
191  space_left = vlib_buffer_space_left_at_end (vm, b0);
192  /* cant parse chains...
193  * and we need some space for option 82*/
194  if ((b0->flags & VLIB_BUFFER_NEXT_PRESENT) != 0 ||
195  space_left < VPP_DHCP_OPTION82_SIZE)
196  {
197  error0 = DHCP_PROXY_ERROR_PKT_TOO_BIG;
198  next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
199  pkts_too_big++;
200  goto do_trace;
201  }
202 
203  server = &proxy->dhcp_servers[0];
204  vlib_buffer_advance (b0, -(sizeof (*ip0)));
205  ip0 = vlib_buffer_get_current (b0);
206 
207  /* disable UDP checksum */
208  u0->checksum = 0;
209  sum0 = ip0->checksum;
210  old0 = ip0->dst_address.as_u32;
211  new0 = server->dhcp_server.ip4.as_u32;
212  ip0->dst_address.as_u32 = server->dhcp_server.ip4.as_u32;
213  sum0 = ip_csum_update (sum0, old0, new0,
214  ip4_header_t /* structure */ ,
215  dst_address /* changed member */ );
216  ip0->checksum = ip_csum_fold (sum0);
217 
218  sum0 = ip0->checksum;
219  old0 = ip0->src_address.as_u32;
220  new0 = proxy->dhcp_src_address.ip4.as_u32;
221  ip0->src_address.as_u32 = new0;
222  sum0 = ip_csum_update (sum0, old0, new0,
223  ip4_header_t /* structure */ ,
224  src_address /* changed member */ );
225  ip0->checksum = ip_csum_fold (sum0);
226 
227  /* Send to DHCP server via the configured FIB */
228  vnet_buffer (b0)->sw_if_index[VLIB_TX] = server->server_fib_index;
229 
230  h0->gateway_ip_address = proxy->dhcp_src_address.ip4;
231  pkts_to_server++;
232 
233  o = h0->options;
234  end = (void *) vlib_buffer_get_tail (b0);
235 
236  /* TLVs are not performance-friendly... */
237  while (o->option != DHCP_PACKET_OPTION_END && o < end)
238  {
240  {
241  if (DHCP_PACKET_DISCOVER == o->data[0])
242  {
243  is_discover = 1;
244  }
245  }
246  o = (dhcp_option_t *) (o->data + o->length);
247  }
248 
249  if (o->option == DHCP_PACKET_OPTION_END && o <= end)
250  {
251  vnet_main_t *vnm = vnet_get_main ();
252  u16 old_l0, new_l0;
253  ip4_address_t _ia0, *ia0 = &_ia0;
254  dhcp_vss_t *vss;
255  vnet_sw_interface_t *swif;
256 
257  original_sw_if_index = sw_if_index =
258  vnet_buffer (b0)->sw_if_index[VLIB_RX];
259  swif = vnet_get_sw_interface (vnm, sw_if_index);
261  sw_if_index = swif->unnumbered_sw_if_index;
262 
263  /*
264  * Get the first ip4 address on the [client-side]
265  * RX interface, if not unnumbered. otherwise use
266  * the loopback interface's ip address.
267  */
268  ia0 = ip4_interface_first_address (&ip4_main, sw_if_index, 0);
269 
270  if (ia0 == 0)
271  {
272  error0 = DHCP_PROXY_ERROR_NO_INTERFACE_ADDRESS;
273  next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
274  pkts_no_interface_address++;
275  goto do_trace;
276  }
277 
278  /* Add option 82 */
279  o->option = 82; /* option 82 */
280  o->length = 12; /* 12 octets to follow */
281  o->data[0] = 1; /* suboption 1, circuit ID (=FIB id) */
282  o->data[1] = 4; /* length of suboption */
283  u32 *o_ifid = (u32 *) & o->data[2];
284  *o_ifid = clib_host_to_net_u32 (original_sw_if_index);
285  o->data[6] = 5; /* suboption 5 (client RX intfc address) */
286  o->data[7] = 4; /* length 4 */
287  u32 *o_addr = (u32 *) & o->data[8];
288  *o_addr = ia0->as_u32;
289  o->data[12] = DHCP_PACKET_OPTION_END;
290 
291  vss = dhcp_get_vss_info (dpm, fib_index, FIB_PROTOCOL_IP4);
292  if (vss)
293  {
294  u32 id_len; /* length of VPN ID */
295 
296  if (vss->vss_type == VSS_TYPE_VPN_ID)
297  {
298  id_len = sizeof (vss->vpn_id); /* vpn_id is 7 bytes */
299  memcpy (&o->data[15], vss->vpn_id, id_len);
300  }
301  else if (vss->vss_type == VSS_TYPE_ASCII)
302  {
303  id_len = vec_len (vss->vpn_ascii_id);
304  memcpy (&o->data[15], vss->vpn_ascii_id, id_len);
305  }
306  else /* must be VSS_TYPE_DEFAULT, no VPN ID */
307  id_len = 0;
308 
309  o->data[12] = 151; /* vss suboption */
310  o->data[13] = id_len + 1; /* length: vss_type + id_len */
311  o->data[14] = vss->vss_type; /* vss option type */
312  o->data[15 + id_len] = 152; /* vss control suboption */
313  o->data[16 + id_len] = 0; /* length */
314  o->data[17 + id_len] = DHCP_PACKET_OPTION_END; /* "end-of-options" (0xFF) */
315  /* 5 bytes for suboption headers 151+len, 152+len and 0xFF */
316  o->length += id_len + 5;
317  }
318 
319  len = o->length + 3;
320  b0->current_length += len;
321  /* Fix IP header length and checksum */
322  old_l0 = ip0->length;
323  new_l0 = clib_net_to_host_u16 (old_l0);
324  new_l0 += len;
325  new_l0 = clib_host_to_net_u16 (new_l0);
326  ip0->length = new_l0;
327  sum0 = ip0->checksum;
328  sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
329  length /* changed member */ );
330  ip0->checksum = ip_csum_fold (sum0);
331 
332  /* Fix UDP length */
333  new_l0 = clib_net_to_host_u16 (u0->length);
334  new_l0 += len;
335  u0->length = clib_host_to_net_u16 (new_l0);
336  }
337  else
338  {
340  (vm, dhcp_proxy_to_server_node.index,
341  DHCP_PROXY_ERROR_OPTION_82_ERROR, 1);
342  }
343 
344  next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP;
345 
346  /*
347  * If we have multiple servers configured and this is the
348  * client's discover message, then send copies to each of
349  * those servers
350  */
351  if (is_discover && vec_len (proxy->dhcp_servers) > 1)
352  {
353  u32 ii;
354 
355  for (ii = 1; ii < vec_len (proxy->dhcp_servers); ii++)
356  {
357  vlib_buffer_t *c0;
358  u32 ci0;
359 
360  c0 = vlib_buffer_copy (vm, b0);
361  if (c0 == NULL)
362  {
364  (vm, dhcp_proxy_to_server_node.index,
365  DHCP_PROXY_ERROR_ALLOC_FAIL, 1);
366  continue;
367  }
369  ci0 = vlib_get_buffer_index (vm, c0);
370  server = &proxy->dhcp_servers[ii];
371 
372  ip0 = vlib_buffer_get_current (c0);
373 
374  sum0 = ip0->checksum;
375  old0 = ip0->dst_address.as_u32;
376  new0 = server->dhcp_server.ip4.as_u32;
377  ip0->dst_address.as_u32 = server->dhcp_server.ip4.as_u32;
378  sum0 = ip_csum_update (sum0, old0, new0,
379  ip4_header_t /* structure */ ,
380  dst_address /* changed member */ );
381  ip0->checksum = ip_csum_fold (sum0);
382 
383  to_next[0] = ci0;
384  to_next += 1;
385  n_left_to_next -= 1;
386 
387  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
388  to_next, n_left_to_next,
389  ci0, next0);
390 
391  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
392  {
393  dhcp_proxy_trace_t *tr;
394 
395  tr = vlib_add_trace (vm, node, c0, sizeof (*tr));
396  tr->which = 0; /* to server */
397  tr->error = error0;
398  tr->original_sw_if_index = original_sw_if_index;
399  tr->sw_if_index = sw_if_index;
400  if (next0 == DHCP_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP)
402  server->dhcp_server.ip4.as_u32;
403  }
404 
405  if (PREDICT_FALSE (0 == n_left_to_next))
406  {
407  vlib_put_next_frame (vm, node, next_index,
408  n_left_to_next);
409  vlib_get_next_frame (vm, node, next_index,
410  to_next, n_left_to_next);
411  }
412  }
413  }
414  do_trace:
415  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
416  {
417  dhcp_proxy_trace_t *tr = vlib_add_trace (vm, node,
418  b0, sizeof (*tr));
419  tr->which = 0; /* to server */
420  tr->error = error0;
421  tr->original_sw_if_index = original_sw_if_index;
422  tr->sw_if_index = sw_if_index;
423  if (next0 == DHCP_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP)
425  proxy->dhcp_servers[0].dhcp_server.ip4.as_u32;
426  }
427 
428  do_enqueue:
429  to_next[0] = bi0;
430  to_next += 1;
431  n_left_to_next -= 1;
432 
433  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
434  to_next, n_left_to_next,
435  bi0, next0);
436  }
437 
438  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
439  }
441  DHCP_PROXY_ERROR_RELAY_TO_CLIENT,
442  pkts_to_client);
444  DHCP_PROXY_ERROR_RELAY_TO_SERVER,
445  pkts_to_server);
447  DHCP_PROXY_ERROR_NO_SERVER, pkts_no_server);
449  DHCP_PROXY_ERROR_NO_INTERFACE_ADDRESS,
450  pkts_no_interface_address);
452  DHCP_PROXY_ERROR_PKT_TOO_BIG, pkts_too_big);
453  return from_frame->n_vectors;
454 }
455 
456 /* *INDENT-OFF* */
458  .function = dhcp_proxy_to_server_input,
459  .name = "dhcp-proxy-to-server",
460  /* Takes a vector of packets. */
461  .vector_size = sizeof (u32),
462 
463  .n_errors = DHCP_PROXY_N_ERROR,
464  .error_strings = dhcp_proxy_error_strings,
465 
466  .n_next_nodes = DHCP_PROXY_TO_SERVER_INPUT_N_NEXT,
467  .next_nodes = {
468 #define _(s,n) [DHCP_PROXY_TO_SERVER_INPUT_NEXT_##s] = n,
470 #undef _
471  },
472 
473  .format_buffer = format_dhcp_proxy_header_with_length,
474  .format_trace = format_dhcp_proxy_trace,
475 #if 0
476  .unformat_buffer = unformat_dhcp_proxy_header,
477 #endif
478 };
479 /* *INDENT-ON* */
480 
481 static uword
483  vlib_node_runtime_t * node,
484  vlib_frame_t * from_frame)
485 {
486  u32 n_left_from, *from;
489  vnet_main_t *vnm = vnet_get_main ();
490  ip4_main_t *im = &ip4_main;
491 
492  from = vlib_frame_vector_args (from_frame);
493  n_left_from = from_frame->n_vectors;
494 
495  while (n_left_from > 0)
496  {
497  u32 bi0;
498  vlib_buffer_t *b0;
499  udp_header_t *u0;
500  dhcp_header_t *h0;
501  ip4_header_t *ip0 = 0;
502  ip4_address_t *ia0 = 0;
503  u32 old0, new0;
504  ip_csum_t sum0;
506  ethernet_header_t *mac0;
507  vnet_hw_interface_t *hi0;
508  vlib_frame_t *f0;
509  u32 *to_next0;
510  u32 sw_if_index = ~0;
511  vnet_sw_interface_t *si0;
512  u32 error0 = (u32) ~ 0;
513  vnet_sw_interface_t *swif;
514  u32 fib_index;
515  dhcp_proxy_t *proxy;
516  dhcp_server_t *server;
517  u32 original_sw_if_index = (u32) ~ 0;
518  ip4_address_t relay_addr = {
519  .as_u32 = 0,
520  };
521 
522  bi0 = from[0];
523  from += 1;
524  n_left_from -= 1;
525 
526  b0 = vlib_get_buffer (vm, bi0);
527  h0 = vlib_buffer_get_current (b0);
528 
529  /*
530  * udp_local hands us the DHCP header, need udp hdr,
531  * ip hdr to relay to client
532  */
533  vlib_buffer_advance (b0, -(sizeof (*u0)));
534  u0 = vlib_buffer_get_current (b0);
535 
536  vlib_buffer_advance (b0, -(sizeof (*ip0)));
537  ip0 = vlib_buffer_get_current (b0);
538 
539  /* Consumed by dhcp client code? */
540  if (dhcp_client_for_us (bi0, b0, ip0, u0, h0))
541  continue;
542 
543  if (1 /* dpm->insert_option_82 */ )
544  {
545  /* linearize needed to "unclone" and scan options */
546  int rv = vlib_buffer_chain_linearize (vm, b0);
547  if ((b0->flags & VLIB_BUFFER_NEXT_PRESENT) != 0 || !rv)
548  {
549  error0 = DHCP_PROXY_ERROR_PKT_TOO_BIG;
550  goto drop_packet;
551  }
552 
553  dhcp_option_t *o = h0->options, *end =
554  (void *) vlib_buffer_get_tail (b0);
555 
556  /* Parse through TLVs looking for option 82.
557  The circuit-ID is the FIB number we need
558  to track down the client-facing interface */
559 
560  while (o->option != DHCP_PACKET_OPTION_END && o < end)
561  {
562  if (o->option == 82)
563  {
564  u32 vss_exist = 0;
565  u32 vss_ctrl = 0;
566  dhcp_option_t *sub = (dhcp_option_t *) & o->data[0];
567  dhcp_option_t *subend =
568  (dhcp_option_t *) (o->data + o->length);
569  while (sub->option != DHCP_PACKET_OPTION_END
570  && sub < subend)
571  {
572  /* If this is one of ours, it will have
573  total length 12, circuit-id suboption type,
574  and the sw_if_index */
575  if (sub->option == 1 && sub->length == 4)
576  {
577  sw_if_index = ((sub->data[0] << 24) |
578  (sub->data[1] << 16) |
579  (sub->data[2] << 8) |
580  (sub->data[3]));
581  }
582  else if (sub->option == 5 && sub->length == 4)
583  {
584  relay_addr.as_u8[0] = sub->data[0];
585  relay_addr.as_u8[1] = sub->data[1];
586  relay_addr.as_u8[2] = sub->data[2];
587  relay_addr.as_u8[3] = sub->data[3];
588  }
589  else if (sub->option == 151 &&
590  sub->length == 7 && sub->data[0] == 1)
591  vss_exist = 1;
592  else if (sub->option == 152 && sub->length == 0)
593  vss_ctrl = 1;
594  sub = (dhcp_option_t *) (sub->data + sub->length);
595  }
596  if (vss_ctrl && vss_exist)
598  (vm, dhcp_proxy_to_client_node.index,
599  DHCP_PROXY_ERROR_OPTION_82_VSS_NOT_PROCESSED, 1);
600 
601  }
602  o = (dhcp_option_t *) (o->data + o->length);
603  }
604  }
605 
606  if (sw_if_index == (u32) ~ 0)
607  {
608  error0 = DHCP_PROXY_ERROR_NO_OPTION_82;
609 
610  drop_packet:
612  error0, 1);
614  to_next0 = vlib_frame_vector_args (f0);
615  to_next0[0] = bi0;
616  f0->n_vectors = 1;
618  goto do_trace;
619  }
620 
621  if (relay_addr.as_u32 == 0)
622  {
623  error0 = DHCP_PROXY_ERROR_BAD_OPTION_82_ADDR;
624  goto drop_packet;
625  }
626 
627  if (sw_if_index >= vec_len (im->fib_index_by_sw_if_index))
628  {
629  error0 = DHCP_PROXY_ERROR_BAD_OPTION_82_ITF;
630  goto drop_packet;
631  }
632 
633  fib_index = im->fib_index_by_sw_if_index[sw_if_index];
634  proxy = dhcp_get_proxy (dpm, fib_index, FIB_PROTOCOL_IP4);
635 
636  if (PREDICT_FALSE (NULL == proxy))
637  {
638  error0 = DHCP_PROXY_ERROR_NO_SERVER;
639  goto drop_packet;
640  }
641 
642  vec_foreach (server, proxy->dhcp_servers)
643  {
644  if (ip0->src_address.as_u32 == server->dhcp_server.ip4.as_u32)
645  {
646  goto server_found;
647  }
648  }
649 
650  error0 = DHCP_PROXY_ERROR_BAD_SVR_FIB_OR_ADDRESS;
651  goto drop_packet;
652 
653  server_found:
654  vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index;
655 
656  swif = vnet_get_sw_interface (vnm, sw_if_index);
657  original_sw_if_index = sw_if_index;
659  sw_if_index = swif->unnumbered_sw_if_index;
660 
661  ia0 = ip4_interface_first_address (&ip4_main, sw_if_index, 0);
662  if (ia0 == 0)
663  {
664  error0 = DHCP_PROXY_ERROR_NO_INTERFACE_ADDRESS;
665  goto drop_packet;
666  }
667 
668  if (relay_addr.as_u32 != ia0->as_u32)
669  {
670  error0 = DHCP_PROXY_ERROR_BAD_YIADDR;
671  goto drop_packet;
672  }
673 
674  u0->checksum = 0;
675  u0->dst_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcp_to_client);
676  sum0 = ip0->checksum;
677  old0 = ip0->dst_address.as_u32;
678  new0 = 0xFFFFFFFF;
679  ip0->dst_address.as_u32 = new0;
680  sum0 = ip_csum_update (sum0, old0, new0, ip4_header_t /* structure */ ,
681  dst_address /* offset of changed member */ );
682  ip0->checksum = ip_csum_fold (sum0);
683 
684  sum0 = ip0->checksum;
685  old0 = ip0->src_address.as_u32;
686  new0 = ia0->as_u32;
687  ip0->src_address.as_u32 = new0;
688  sum0 = ip_csum_update (sum0, old0, new0, ip4_header_t /* structure */ ,
689  src_address /* offset of changed member */ );
690  ip0->checksum = ip_csum_fold (sum0);
691 
692  vlib_buffer_advance (b0, -(sizeof (ethernet_header_t)));
693  si0 = vnet_get_sw_interface (vnm, original_sw_if_index);
694  if (si0->type == VNET_SW_INTERFACE_TYPE_SUB)
695  vlib_buffer_advance (b0, -4 /* space for VLAN tag */ );
696 
697  mac0 = vlib_buffer_get_current (b0);
698 
699  hi0 = vnet_get_sup_hw_interface (vnm, original_sw_if_index);
700  ei0 = pool_elt_at_index (em->interfaces, hi0->hw_instance);
701  clib_memcpy (mac0->src_address, ei0->address, sizeof (ei0->address));
702  clib_memset (mac0->dst_address, 0xff, sizeof (mac0->dst_address));
703  mac0->type = (si0->type == VNET_SW_INTERFACE_TYPE_SUB) ?
704  clib_net_to_host_u16 (0x8100) : clib_net_to_host_u16 (0x0800);
705 
706  if (si0->type == VNET_SW_INTERFACE_TYPE_SUB)
707  {
708  u32 *vlan_tag = (u32 *) (mac0 + 1);
709  u32 tmp;
710  tmp = (si0->sub.id << 16) | 0x0800;
711  *vlan_tag = clib_host_to_net_u32 (tmp);
712  }
713 
714  /* $$$ This needs to be rewritten, for sure */
716  to_next0 = vlib_frame_vector_args (f0);
717  to_next0[0] = bi0;
718  f0->n_vectors = 1;
720 
721  do_trace:
722  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
723  {
724  dhcp_proxy_trace_t *tr = vlib_add_trace (vm, node,
725  b0, sizeof (*tr));
726  tr->which = 1; /* to client */
727  tr->trace_ip4_address.as_u32 = ia0 ? ia0->as_u32 : 0;
728  tr->error = error0;
729  tr->original_sw_if_index = original_sw_if_index;
730  tr->sw_if_index = sw_if_index;
731  }
732  }
733 
734  return from_frame->n_vectors;
735 }
736 
737 /* *INDENT-OFF* */
739  .function = dhcp_proxy_to_client_input,
740  .name = "dhcp-proxy-to-client",
741  /* Takes a vector of packets. */
742  .vector_size = sizeof (u32),
743 
744  .n_errors = DHCP_PROXY_N_ERROR,
745  .error_strings = dhcp_proxy_error_strings,
746  .format_buffer = format_dhcp_proxy_header_with_length,
747  .format_trace = format_dhcp_proxy_trace,
748 #if 0
749  .unformat_buffer = unformat_dhcp_proxy_header,
750 #endif
751 };
752 /* *INDENT-ON* */
753 
754 void
756 {
758  vlib_main_t *vm = dm->vlib_main;
759  int port_regs_diff = dm->udp_ports_registered ^ ports;
760 
761  if (!port_regs_diff)
762  return;
763 
764  if ((port_regs_diff & DHCP_PORT_REG_CLIENT) & ports)
765  udp_register_dst_port (vm, UDP_DST_PORT_dhcp_to_client,
766  dhcp_proxy_to_client_node.index, 1 /* is_ip4 */ );
767 
768  if ((port_regs_diff & DHCP_PORT_REG_SERVER) & ports)
769  udp_register_dst_port (vm, UDP_DST_PORT_dhcp_to_server,
770  dhcp_proxy_to_server_node.index, 1 /* is_ip4 */ );
771 
772  dm->udp_ports_registered |= ports;
773 }
774 
775 static clib_error_t *
777 {
780 
781  error_drop_node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
782  dm->error_drop_node_index = error_drop_node->index;
783  dm->vlib_main = vm;
784 
785  return 0;
786 }
787 
788 
790 
791 int
792 dhcp4_proxy_set_server (ip46_address_t * addr,
793  ip46_address_t * src_addr,
794  u32 rx_table_id, u32 server_table_id, int is_del)
795 {
796  u32 rx_fib_index = 0;
797  int rc = 0;
798 
799  const fib_prefix_t all_1s = {
800  .fp_len = 32,
801  .fp_addr.ip4.as_u32 = 0xffffffff,
802  .fp_proto = FIB_PROTOCOL_IP4,
803  };
804 
805  if (ip46_address_is_zero (addr))
806  return VNET_API_ERROR_INVALID_DST_ADDRESS;
807 
808  if (ip46_address_is_zero (src_addr))
809  return VNET_API_ERROR_INVALID_SRC_ADDRESS;
810 
812 
814  rx_table_id,
816 
817  if (is_del)
818  {
819  if (dhcp_proxy_server_del (FIB_PROTOCOL_IP4, rx_fib_index,
820  addr, server_table_id))
821  {
822  fib_table_entry_special_remove (rx_fib_index,
823  &all_1s, FIB_SOURCE_DHCP);
825  }
826  }
827  else
828  {
830  addr, src_addr,
831  rx_fib_index, server_table_id))
832  {
833  fib_table_entry_special_add (rx_fib_index,
834  &all_1s,
837  }
838  }
840 
841  return (rc);
842 }
843 
844 static clib_error_t *
846  unformat_input_t * input,
847  vlib_cli_command_t * cmd)
848 {
849  ip46_address_t server_addr, src_addr;
850  u32 server_table_id = 0, rx_table_id = 0;
851  int is_del = 0;
852  int set_src = 0, set_server = 0;
853 
854  clib_memset (&server_addr, 0, sizeof (server_addr));
855  clib_memset (&src_addr, 0, sizeof (src_addr));
856 
858  {
859  if (unformat (input, "server %U",
860  unformat_ip4_address, &server_addr.ip4))
861  set_server = 1;
862  else if (unformat (input, "server-fib-id %d", &server_table_id))
863  ;
864  else if (unformat (input, "rx-fib-id %d", &rx_table_id))
865  ;
866  else if (unformat (input, "src-address %U",
867  unformat_ip4_address, &src_addr.ip4))
868  set_src = 1;
869  else if (unformat (input, "delete") || unformat (input, "del"))
870  is_del = 1;
871  else
872  break;
873  }
874 
875  if (is_del || (set_server && set_src))
876  {
877  int rv;
878 
879  rv = dhcp4_proxy_set_server (&server_addr, &src_addr, rx_table_id,
880  server_table_id, is_del);
881  switch (rv)
882  {
883  case 0:
884  return 0;
885 
886  case VNET_API_ERROR_INVALID_DST_ADDRESS:
887  return clib_error_return (0, "Invalid server address");
888 
889  case VNET_API_ERROR_INVALID_SRC_ADDRESS:
890  return clib_error_return (0, "Invalid src address");
891 
892  case VNET_API_ERROR_NO_SUCH_ENTRY:
893  return clib_error_return
894  (0, "Fib id %d: no per-fib DHCP server configured", rx_table_id);
895 
896  default:
897  return clib_error_return (0, "BUG: rv %d", rv);
898  }
899  }
900  else
901  return clib_error_return (0, "parse error`%U'",
902  format_unformat_error, input);
903 }
904 
905 /* *INDENT-OFF* */
906 VLIB_CLI_COMMAND (dhcp_proxy_set_command, static) = {
907  .path = "set dhcp proxy",
908  .short_help = "set dhcp proxy [del] server <ip-addr> src-address <ip-addr> [server-fib-id <n>] [rx-fib-id <n>]",
909  .function = dhcp4_proxy_set_command_fn,
910 };
911 /* *INDENT-ON* */
912 
913 static u8 *
914 format_dhcp4_proxy_server (u8 * s, va_list * args)
915 {
916  dhcp_proxy_t *proxy = va_arg (*args, dhcp_proxy_t *);
917  ip4_fib_t *rx_fib, *server_fib;
918  dhcp_server_t *server;
919 
920  if (proxy == 0)
921  {
922  s = format (s, "%=14s%=16s%s", "RX FIB", "Src Address",
923  "Servers FIB,Address");
924  return s;
925  }
926 
927  rx_fib = ip4_fib_get (proxy->rx_fib_index);
928 
929  s = format (s, "%=14u%=16U",
930  rx_fib->table_id,
932 
933  vec_foreach (server, proxy->dhcp_servers)
934  {
935  server_fib = ip4_fib_get (server->server_fib_index);
936  s = format (s, "%u,%U ",
937  server_fib->table_id,
939  }
940  return s;
941 }
942 
943 static int
945 {
946  vlib_main_t *vm = ctx;
947 
948  vlib_cli_output (vm, "%U", format_dhcp4_proxy_server, server);
949 
950  return (1);
951 }
952 
953 static clib_error_t *
955  unformat_input_t * input,
956  vlib_cli_command_t * cmd)
957 {
959  NULL /* header line */ );
960 
962 
963  return (NULL);
964 }
965 
966 /* *INDENT-OFF* */
967 VLIB_CLI_COMMAND (dhcp_proxy_show_command, static) = {
968  .path = "show dhcp proxy",
969  .short_help = "Display dhcp proxy server info",
970  .function = dhcp4_proxy_show_command_fn,
971 };
972 /* *INDENT-ON* */
973 
974 static clib_error_t *
976  unformat_input_t * input, vlib_cli_command_t * cmd)
977 {
978  u8 is_del = 0, vss_type = VSS_TYPE_DEFAULT;
979  u32 oui = 0, fib_id = 0, tbl_id = ~0;
980  u8 *vpn_ascii_id = 0;
981 
983  {
984  if (unformat (input, "table %d", &tbl_id))
985  ;
986  else if (unformat (input, "oui %d", &oui))
987  vss_type = VSS_TYPE_VPN_ID;
988  else if (unformat (input, "vpn-id %d", &fib_id))
989  vss_type = VSS_TYPE_VPN_ID;
990  else if (unformat (input, "vpn-ascii-id %s", &vpn_ascii_id))
991  vss_type = VSS_TYPE_ASCII;
992  else if (unformat (input, "delete") || unformat (input, "del"))
993  is_del = 1;
994  else
995  break;
996  }
997 
998  if (tbl_id == ~0)
999  return clib_error_return (0, "no table ID specified.");
1000 
1001  int rv = dhcp_proxy_set_vss (FIB_PROTOCOL_IP4, tbl_id, vss_type,
1002  vpn_ascii_id, oui, fib_id, is_del);
1003  switch (rv)
1004  {
1005  case 0:
1006  return 0;
1007  case VNET_API_ERROR_NO_SUCH_ENTRY:
1008  return clib_error_return (0,
1009  "option 82 vss for table %d not found in in pool.",
1010  tbl_id);
1011  default:
1012  return clib_error_return (0, "BUG: rv %d", rv);
1013 
1014  }
1015 }
1016 
1017 /* *INDENT-OFF* */
1018 VLIB_CLI_COMMAND (dhcp_proxy_vss_command,static) = {
1019  .path = "set dhcp option-82 vss",
1020  .short_help = "set dhcp option-82 vss [del] table <table id> [oui <n> vpn-id <n> | vpn-ascii-id <text>]",
1021  .function = dhcp_option_82_vss_fn,
1022 };
1023 /* *INDENT-ON* */
1024 
1025 static clib_error_t *
1027  unformat_input_t * input, vlib_cli_command_t * cmd)
1028 {
1030 
1031  return (NULL);
1032 }
1033 
1034 /* *INDENT-OFF* */
1035 VLIB_CLI_COMMAND (dhcp_proxy_vss_show_command, static) = {
1036  .path = "show dhcp vss",
1037  .short_help = "show dhcp VSS",
1038  .function = dhcp_vss_show_command_fn,
1039 };
1040 /* *INDENT-ON* */
1041 
1042 static clib_error_t *
1044  unformat_input_t * input,
1045  vlib_cli_command_t * cmd)
1046 {
1047  vnet_main_t *vnm = vnet_get_main ();
1048  u32 sw_if_index0 = 0, sw_if_index;
1049  vnet_sw_interface_t *swif;
1050  ip4_address_t *ia0;
1051 
1052  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1053  {
1054 
1055  if (unformat (input, "%U",
1056  unformat_vnet_sw_interface, vnm, &sw_if_index0))
1057  {
1058  swif = vnet_get_sw_interface (vnm, sw_if_index0);
1060  swif->unnumbered_sw_if_index : sw_if_index0;
1062  if (ia0)
1063  {
1064  vlib_cli_output (vm, "%=20s%=20s", "interface",
1065  "source IP address");
1066 
1067  vlib_cli_output (vm, "%=20U%=20U",
1069  vnm, sw_if_index0, format_ip4_address, ia0);
1070  }
1071  else
1072  vlib_cli_output (vm, "%=34s %=20U",
1073  "No IPv4 address configured on",
1075  }
1076  else
1077  break;
1078  }
1079 
1080  return 0;
1081 }
1082 
1083 /* *INDENT-OFF* */
1084 VLIB_CLI_COMMAND (dhcp_proxy_address_show_command,static) = {
1085  .path = "show dhcp option-82-address interface",
1086  .short_help = "show dhcp option-82-address interface <interface>",
1088 };
1089 /* *INDENT-ON* */
1090 
1091 /*
1092  * fd.io coding-style-patch-verification: ON
1093  *
1094  * Local Variables:
1095  * eval: (c-set-style "gnu")
1096  * End:
1097  */
static vlib_node_registration_t dhcp_proxy_to_client_node
(constructor) VLIB_REGISTER_NODE (dhcp_proxy_to_client_node)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
static dhcp_vss_t * dhcp_get_vss_info(dhcp_proxy_main_t *dm, u32 rx_fib_index, fib_protocol_t proto)
Get the VSS data for the FIB index.
Definition: dhcp_proxy.h:255
static u8 * vlib_buffer_get_tail(vlib_buffer_t *b)
Get pointer to the end of buffer&#39;s data.
Definition: buffer.h:310
#define CLIB_UNUSED(x)
Definition: clib.h:83
ip4_address_t src_address
Definition: ip4_packet.h:170
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
void dhcp_vss_walk(fib_protocol_t proto, dhcp_vss_walk_fn_t fn, void *ctx)
Walk/Visit each DHCP proxy VSS.
Definition: dhcp_proxy.c:87
dhcp_server_t * dhcp_servers
The set of DHCP servers to which messages are relayed.
Definition: dhcp_proxy.h:111
static uword dhcp_proxy_to_client_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
void dhcp_proxy_walk(fib_protocol_t proto, dhcp_proxy_walk_fn_t fn, void *ctx)
Walk/Visit each DHCP proxy server.
Definition: dhcp_proxy.c:67
static clib_error_t * dhcp4_proxy_show_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define VPP_DHCP_OPTION82_SIZE
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 index
Definition: node.h:280
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
Definition: ip4_forward.c:278
dhcp_proxy_main_t dhcp_proxy_main
Shard 4/6 instance of DHCP main.
Definition: dhcp_proxy.c:25
u8 src_address[6]
Definition: packet.h:56
int dhcp_vss_show_walk(dhcp_vss_t *vss, u32 rx_table_id, void *ctx)
Show (on CLI) a VSS config during a show walk.
Definition: dhcp_proxy.c:259
static uword dhcp_proxy_to_server_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
ip46_address_t dhcp_src_address
The source address to use in relayed messaes.
Definition: dhcp_proxy.h:126
The Virtual Sub-net Selection information for a given RX FIB.
Definition: dhcp_proxy.h:57
int dhcp_client_for_us(u32 bi, vlib_buffer_t *b, ip4_header_t *ip, udp_header_t *udp, dhcp_header_t *dhcp)
Definition: client.c:274
u32 rx_fib_index
The FIB index (not the external Table-ID) in which the client is resides.
Definition: dhcp_proxy.h:132
format_function_t format_ip46_address
Definition: format.h:61
uword ip_csum_t
Definition: ip_packet.h:219
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:121
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
unformat_function_t unformat_vnet_sw_interface
vlib_node_registration_t error_drop_node
(constructor) VLIB_REGISTER_NODE (error_drop_node)
Definition: drop.c:258
u8 vss_type
VSS type as defined in RFC 6607: 0 for NVT ASCII VPN Identifier 1 for RFC 2685 VPN-ID of 7 octects - ...
Definition: dhcp_proxy.h:65
vhost_vring_addr_t addr
Definition: vhost_user.h:147
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
static vlib_buffer_t * vlib_buffer_copy(vlib_main_t *vm, vlib_buffer_t *b)
Definition: buffer_funcs.h:964
#define clib_memcpy(d, s, n)
Definition: string.h:180
format_function_t format_ip4_address
Definition: format.h:75
unformat_function_t unformat_ip4_address
Definition: format.h:70
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
u32 table_id
Definition: ip4_fib.h:54
void fib_table_entry_special_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Remove a &#39;special&#39; entry from the FIB.
Definition: fib_table.c:407
ip4_address_t dst_address
Definition: ip4_packet.h:170
u8 dst_address[6]
Definition: packet.h:55
static vlib_node_registration_t dhcp_proxy_to_server_node
(constructor) VLIB_REGISTER_NODE (dhcp_proxy_to_server_node)
Aggregate type for a prefix.
Definition: fib_types.h:203
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:185
static clib_error_t * dhcp4_proxy_set_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static dhcp_proxy_t * dhcp_get_proxy(dhcp_proxy_main_t *dm, u32 rx_fib_index, fib_protocol_t proto)
Get the DHCP proxy server data for the FIB index.
Definition: dhcp_proxy.h:275
#define clib_error_return(e, args...)
Definition: error.h:99
#define VSS_TYPE_ASCII
Definition: dhcp_proxy.h:66
int dhcp_proxy_server_add(fib_protocol_t proto, ip46_address_t *addr, ip46_address_t *src_address, u32 rx_fib_index, u32 server_table_id)
Add a new DHCP proxy server configuration.
Definition: dhcp_proxy.c:184
unsigned int u32
Definition: types.h:88
u16 fp_len
The mask length.
Definition: fib_types.h:207
#define VSS_TYPE_DEFAULT
Definition: dhcp_proxy.h:69
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
Definition: buffer_funcs.h:257
u32 server_fib_index
The FIB index (not the external Table-ID) in which the server is reachable.
Definition: dhcp_proxy.h:95
static u8 * format_dhcp4_proxy_server(u8 *s, va_list *args)
static u32 vlib_buffer_chain_linearize(vlib_main_t *vm, vlib_buffer_t *b)
Definition: fib_entry.h:286
dhcp_port_reg_flags_t
Definition: dhcp_proxy.h:48
Collection of global DHCP proxy data.
Definition: dhcp_proxy.h:140
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
vnet_sub_interface_t sub
Definition: interface.h:723
long ctx[MAX_CONNS]
Definition: main.c:144
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
dhcp_proxy_to_server_input_next_t
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
Definition: main.c:194
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
#define PREDICT_FALSE(x)
Definition: clib.h:112
vnet_sw_interface_flags_t flags
Definition: interface.h:703
vlib_main_t * vlib_main
Definition: dhcp_proxy.h:160
vl_api_address_union_t src_address
Definition: ip_types.api:97
static char * dhcp_proxy_error_strings[]
int dhcp_proxy_set_vss(fib_protocol_t proto, u32 tbl_id, u8 vss_type, u8 *vpn_ascii_id, u32 oui, u32 vpn_index, u8 is_del)
Configure/set a new VSS info.
Definition: dhcp_proxy.c:309
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:218
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:338
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
Definition: fib_table.c:1253
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1150
u8 len
Definition: ip_types.api:90
static clib_error_t * dhcp4_proxy_init(vlib_main_t *vm)
fib_node_index_t fib_table_entry_special_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags)
Add a &#39;special&#39; entry to the FIB.
Definition: fib_table.c:388
The IPv4 FIB.
Definition: ip4_fib.h:39
dhcp_option_t options[0]
Definition: dhcp4_packet.h:51
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
u8 * vpn_ascii_id
Type 0 ASCII VPN Identifier.
Definition: dhcp_proxy.h:77
u16 n_vectors
Definition: node.h:397
vlib_main_t * vm
Definition: buffer.c:323
static clib_error_t * dhcp_option_82_address_show_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static ip4_fib_t * ip4_fib_get(u32 index)
Get the FIB at the given index.
Definition: ip4_fib.h:113
A representation of a single DHCP Server within a given VRF config.
Definition: dhcp_proxy.h:83
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:456
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
static u32 vlib_buffer_space_left_at_end(vlib_main_t *vm, vlib_buffer_t *b)
void fib_table_lock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Release a reference counting lock on the table.
Definition: fib_table.c:1273
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:161
int dhcp4_proxy_set_server(ip46_address_t *addr, ip46_address_t *src_addr, u32 rx_table_id, u32 server_table_id, int is_del)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:515
ip46_address_t dhcp_server
The address of the DHCP server to which to relay the client&#39;s messages.
Definition: dhcp_proxy.h:89
static u8 * format_dhcp_proxy_trace(u8 *s, va_list *args)
#define foreach_dhcp_proxy_to_server_input_next
ip4_address_t gateway_ip_address
Definition: dhcp4_packet.h:46
static clib_error_t * dhcp_option_82_vss_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
IPv4 main type.
Definition: ip4.h:105
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, fib_source_t src)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1139
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:248
static clib_error_t * dhcp_vss_show_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
ip4_address_t trace_ip4_address
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
struct _vlib_node_registration vlib_node_registration_t
A DHCP proxy representation fpr per-client VRF config.
Definition: dhcp_proxy.h:101
Definition: defs.h:47
int dhcp_proxy_server_del(fib_protocol_t proto, u32 rx_fib_index, ip46_address_t *addr, u32 server_table_id)
Delete a DHCP proxy config.
Definition: dhcp_proxy.c:144
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u8 vpn_id[7]
Type 1 VPN-ID.
Definition: dhcp_proxy.h:73
DHCP.
Definition: fib_entry.h:99
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
Definition: buffer.h:489
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
#define ip_csum_update(sum, old, new, type, field)
Definition: ip_packet.h:269
void dhcp_maybe_register_udp_ports(dhcp_port_reg_flags_t ports)
Register the dhcp client and/or server ports, if not already done.
#define VSS_TYPE_VPN_ID
Definition: dhcp_proxy.h:67
static u8 * format_dhcp_proxy_header_with_length(u8 *s, va_list *args)
static ethernet_main_t * vnet_get_ethernet_main(void)
Definition: ethernet.h:536
#define vnet_buffer(b)
Definition: buffer.h:365
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
vnet_sw_interface_type_t type
Definition: interface.h:701
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1076
#define vec_foreach(var, vec)
Vector iterator.
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:468
ethernet_interface_t * interfaces
Definition: ethernet.h:272
#define ip46_address_is_zero(ip46)
Definition: ip6_packet.h:93
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:772
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
static int dhcp4_proxy_show_walk(dhcp_proxy_t *server, void *ctx)
static u16 ip_csum_fold(ip_csum_t c)
Definition: ip_packet.h:275
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
Definition: defs.h:46
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171