73b19150e8db4ce77a868cd3d21cd4773561778e
[demo.git] / vnfs / vCPE / vpp-option-82-for-vbrg / src / patches / VPP-Add-Option82-Nat-Filter-For-vBRG.patch
1 diff --git a/src/plugins/snat/out2in.c b/src/plugins/snat/out2in.c
2 index 5c12b47..f7c7caf 100644
3 --- a/src/plugins/snat/out2in.c
4 +++ b/src/plugins/snat/out2in.c
5 @@ -1,3 +1,4 @@
6 +
7  /*
8   * Copyright (c) 2016 Cisco and/or its affiliates.
9   * Licensed under the Apache License, Version 2.0 (the "License");
10 @@ -658,6 +659,26 @@ snat_out2in_node_fn (vlib_main_t * vm,
11    n_left_from = frame->n_vectors;
12    next_index = node->cached_next_index;
13  
14 +  //FOR BRG
15 +  ip4_address_t * sdnc_addr = malloc(4);
16 +  char line_input[128];
17 +  char * path = "/opt/config/ip.txt";
18 +  FILE * f = fopen(path, "r");
19 +  if (f == NULL)
20 +    printf("cannot open such file\n");
21 +
22 +  while (fgets(line_input, 128, f) != NULL){
23 +    if (!strcmp(strtok(line_input, " "),"sdnc_ip:")){
24 +      char * ip = strtok(NULL, " ");
25 +      char * num = strtok(ip, ".");
26 +      sdnc_addr->data[0] = atoi(num);
27 +      for (int i = 1; i < 4; i ++){
28 +        num = strtok(NULL, ".");
29 +        sdnc_addr->data[i] = atoi(num);
30 +      }
31 +    }
32 +  }
33 +
34    while (n_left_from > 0)
35      {
36        u32 n_left_to_next;
37 @@ -733,6 +754,13 @@ snat_out2in_node_fn (vlib_main_t * vm,
38  
39            proto0 = ip_proto_to_snat_proto (ip0->protocol);
40  
41 +          //for BRG
42 +          if (PREDICT_TRUE (ip0->src_address.data_u32 != sdnc_addr->data_u32))
43 +            {
44 +              next0 = SNAT_OUT2IN_NEXT_LOOKUP;
45 +              goto trace0;
46 +            }
47 +
48            if (PREDICT_FALSE (proto0 == ~0))
49              {
50                snat_out2in_unknown_proto(sm, b0, ip0, rx_fib_index0);
51 @@ -871,6 +899,13 @@ snat_out2in_node_fn (vlib_main_t * vm,
52  
53            proto1 = ip_proto_to_snat_proto (ip1->protocol);
54  
55 +         //for BRG
56 +          if (PREDICT_TRUE (ip1->src_address.data_u32 != sdnc_addr->data_u32))
57 +            {
58 +              next1 = SNAT_OUT2IN_NEXT_LOOKUP;
59 +              goto trace1;
60 +            }
61 +
62            if (PREDICT_FALSE (proto1 == ~0))
63              {
64                snat_out2in_unknown_proto(sm, b1, ip1, rx_fib_index1);
65 @@ -1033,6 +1068,13 @@ snat_out2in_node_fn (vlib_main_t * vm,
66  
67            proto0 = ip_proto_to_snat_proto (ip0->protocol);
68  
69 +         //for BRG
70 +          if (PREDICT_TRUE (ip0->src_address.data_u32 != sdnc_addr->data_u32))
71 +            {
72 +              next0 = SNAT_OUT2IN_NEXT_LOOKUP;
73 +              goto trace00;
74 +            }
75 +
76            if (PREDICT_FALSE (proto0 == ~0))
77              {
78                snat_out2in_unknown_proto(sm, b0, ip0, rx_fib_index0);
79 diff --git a/src/vnet/dhcp/client.c b/src/vnet/dhcp/client.c
80 index 014f17a..296e1a7 100644
81 --- a/src/vnet/dhcp/client.c
82 +++ b/src/vnet/dhcp/client.c
83 @@ -427,6 +427,16 @@ send_dhcp_pkt (dhcp_client_main_t * dcm, dhcp_client_t * c,
84    clib_memcpy (o->data, c->option_55_data, vec_len(c->option_55_data));
85    o = (dhcp_option_t *) (((uword) o) + (o->length + 2));
86  
87 +  /*send option 82*/
88 +  u8 sub2_len = vec_len(hw->hw_address);
89 +  o->option = 82;
90 +  o->length = sub2_len + 2;
91 +  u8 sub_option = 2;
92 +  clib_memcpy (o->data, &sub_option, 1);
93 +  clib_memcpy (o->data + 1,&sub2_len, 1);
94 +  clib_memcpy (o->data + 2, hw->hw_address, vec_len(hw->hw_address));
95 +  o = (dhcp_option_t *) (((uword) o) + (o->length +2));
96 +
97    /* End of list */
98    o->option = 0xff;
99    o->length = 0;