Fixed bug in vbrg vpp snat patch
[demo.git] / vnfs / vCPE / vpp-option-82-for-vbrg / src / patches / VPP-Add-Option82-Nat-Filter-For-vBRG.patch
1 commit 43028d14c3bfb09c582caa8b610e447118fb71c1
2 Author: Itohan Ukponmwan <itohan.ukponmwan@intel.com>
3 Date:   Fri Nov 17 21:18:23 2017 +0000
4
5     Modified out2in.c and client.c
6
7 diff --git a/src/plugins/snat/out2in.c b/src/plugins/snat/out2in.c
8 index 7de85eb..e2e6cec 100644
9 --- a/src/plugins/snat/out2in.c
10 +++ b/src/plugins/snat/out2in.c
11 @@ -1,3 +1,4 @@
12 +
13  /*
14   * Copyright (c) 2016 Cisco and/or its affiliates.
15   * Licensed under the Apache License, Version 2.0 (the "License");
16 @@ -648,6 +649,25 @@ snat_out2in_node_fn (vlib_main_t * vm,
17    n_left_from = frame->n_vectors;
18    next_index = node->cached_next_index;
19
20 +  //FOR BRG
21 +  ip4_address_t * sdnc_addr = malloc(4);
22 +  char line_input[128];
23 +  char * path = "/opt/config/ip.txt";
24 +  FILE * f = fopen(path, "r");
25 +  if (f != NULL){
26 +    while (fgets(line_input, 128, f) != NULL){
27 +      if (!strcmp(strtok(line_input, " "),"sdnc_ip:")){
28 +        char * ip = strtok(NULL, " ");
29 +        char * num = strtok(ip, ".");
30 +        sdnc_addr->data[0] = atoi(num);
31 +        for (int i = 1; i < 4; i ++){
32 +          num = strtok(NULL, ".");
33 +          sdnc_addr->data[i] = atoi(num);
34 +        }
35 +      }
36 +    }
37 +    fclose(f);
38 +  }
39    while (n_left_from > 0)
40      {
41        u32 n_left_to_next;
42 @@ -723,6 +743,13 @@ snat_out2in_node_fn (vlib_main_t * vm,
43
44            proto0 = ip_proto_to_snat_proto (ip0->protocol);
45
46 +          //for BRG
47 +          if (PREDICT_TRUE (ip0->src_address.data_u32 != sdnc_addr->data_u32))
48 +            {
49 +              next0 = SNAT_OUT2IN_NEXT_LOOKUP;
50 +              goto trace0;
51 +            }
52 +
53            if (PREDICT_FALSE (proto0 == ~0))
54                goto trace0;
55
56 @@ -858,6 +885,13 @@ snat_out2in_node_fn (vlib_main_t * vm,
57
58            proto1 = ip_proto_to_snat_proto (ip1->protocol);
59
60 +         //for BRG
61 +          if (PREDICT_TRUE (ip1->src_address.data_u32 != sdnc_addr->data_u32))
62 +            {
63 +              next1 = SNAT_OUT2IN_NEXT_LOOKUP;
64 +              goto trace1;
65 +            }
66 +
67            if (PREDICT_FALSE (proto1 == ~0))
68                goto trace1;
69
70 @@ -1017,6 +1051,13 @@ snat_out2in_node_fn (vlib_main_t * vm,
71
72            proto0 = ip_proto_to_snat_proto (ip0->protocol);
73  
74 +         //for BRG
75 +          if (PREDICT_TRUE (ip0->src_address.data_u32 != sdnc_addr->data_u32))
76 +            {
77 +              next0 = SNAT_OUT2IN_NEXT_LOOKUP;
78 +              goto trace00;
79 +            }
80 +
81            if (PREDICT_FALSE (proto0 == ~0))
82                goto trace00;
83
84 @@ -1153,6 +1194,7 @@ snat_out2in_node_fn (vlib_main_t * vm,
85    vlib_node_increment_counter (vm, snat_out2in_node.index,
86                                 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
87                                 pkts_processed);
88 +  free(sdnc_addr);
89    return frame->n_vectors;
90  }
91
92 diff --git a/src/vnet/dhcp/client.c b/src/vnet/dhcp/client.c
93 index 7c3f7f6..41bc2c7 100644
94 --- a/src/vnet/dhcp/client.c
95 +++ b/src/vnet/dhcp/client.c
96 @@ -426,6 +426,16 @@ send_dhcp_pkt (dhcp_client_main_t * dcm, dhcp_client_t * c,
97    clib_memcpy (o->data, c->option_55_data, vec_len(c->option_55_data));
98    o = (dhcp_option_t *) (((uword) o) + (o->length + 2));
99
100 +  /*send option 82*/
101 +  u8 sub2_len = vec_len(hw->hw_address);
102 +  o->option = 82;
103 +  o->length = sub2_len + 2;
104 +  u8 sub_option = 2;
105 +  clib_memcpy (o->data, &sub_option, 1);
106 +  clib_memcpy (o->data + 1,&sub2_len, 1);
107 +  clib_memcpy (o->data + 2, hw->hw_address, vec_len(hw->hw_address));
108 +  o = (dhcp_option_t *) (((uword) o) + (o->length +2));
109 +
110    /* End of list */
111    o->option = 0xff;
112    o->length = 0;