aboutsummaryrefslogtreecommitdiffstats
path: root/vnfs/vCPE/vpp-option-82-for-vbrg/src/patches/VPP-Add-Option82-Nat-Filter-For-vBRG.patch
blob: 899ff25ac1b6cf54180d26c70351fb3754848c84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
commit 43028d14c3bfb09c582caa8b610e447118fb71c1
Author: Itohan Ukponmwan <itohan.ukponmwan@intel.com>
Date:   Fri Nov 17 21:18:23 2017 +0000

    Modified out2in.c and client.c

diff --git a/src/plugins/snat/out2in.c b/src/plugins/snat/out2in.c
index 7de85eb..e2e6cec 100644
--- a/src/plugins/snat/out2in.c
+++ b/src/plugins/snat/out2in.c
@@ -1,3 +1,4 @@
+
 /*
  * Copyright (c) 2016 Cisco and/or its affiliates.
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -648,6 +649,25 @@ snat_out2in_node_fn (vlib_main_t * vm,
   n_left_from = frame->n_vectors;
   next_index = node->cached_next_index;

+  //FOR BRG
+  ip4_address_t * sdnc_addr = malloc(4);
+  char line_input[128];
+  char * path = "/opt/config/ip.txt";
+  FILE * f = fopen(path, "r");
+  if (f != NULL){
+    while (fgets(line_input, 128, f) != NULL){
+      if (!strcmp(strtok(line_input, " "),"sdnc_ip:")){
+        char * ip = strtok(NULL, " ");
+        char * num = strtok(ip, ".");
+        sdnc_addr->data[0] = atoi(num);
+        for (int i = 1; i < 4; i ++){
+          num = strtok(NULL, ".");
+          sdnc_addr->data[i] = atoi(num);
+        }
+      }
+    }
+    fclose(f);
+  }
   while (n_left_from > 0)
     {
       u32 n_left_to_next;
@@ -723,6 +743,13 @@ snat_out2in_node_fn (vlib_main_t * vm,

           proto0 = ip_proto_to_snat_proto (ip0->protocol);

+          //for BRG
+          if (PREDICT_TRUE (ip0->src_address.data_u32 != sdnc_addr->data_u32))
+            {
+              next0 = SNAT_OUT2IN_NEXT_LOOKUP;
+              goto trace0;
+            }
+
           if (PREDICT_FALSE (proto0 == ~0))
               goto trace0;

@@ -858,6 +885,13 @@ snat_out2in_node_fn (vlib_main_t * vm,

           proto1 = ip_proto_to_snat_proto (ip1->protocol);

+	  //for BRG
+          if (PREDICT_TRUE (ip1->src_address.data_u32 != sdnc_addr->data_u32))
+            {
+              next1 = SNAT_OUT2IN_NEXT_LOOKUP;
+              goto trace1;
+            }
+
           if (PREDICT_FALSE (proto1 == ~0))
               goto trace1;

@@ -1017,6 +1051,13 @@ snat_out2in_node_fn (vlib_main_t * vm,

           proto0 = ip_proto_to_snat_proto (ip0->protocol);
 
+	  //for BRG
+          if (PREDICT_TRUE (ip0->src_address.data_u32 != sdnc_addr->data_u32))
+            {
+              next0 = SNAT_OUT2IN_NEXT_LOOKUP;
+              goto trace00;
+            }
+
           if (PREDICT_FALSE (proto0 == ~0))
               goto trace00;

@@ -1153,6 +1194,7 @@ snat_out2in_node_fn (vlib_main_t * vm,
   vlib_node_increment_counter (vm, snat_out2in_node.index,
                                SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
                                pkts_processed);
+  free(sdnc_addr);
   return frame->n_vectors;
 }

diff --git a/src/vnet/dhcp/client.c b/src/vnet/dhcp/client.c
index 7c3f7f6..41bc2c7 100644
--- a/src/vnet/dhcp/client.c
+++ b/src/vnet/dhcp/client.c
@@ -426,6 +426,16 @@ send_dhcp_pkt (dhcp_client_main_t * dcm, dhcp_client_t * c,
   clib_memcpy (o->data, c->option_55_data, vec_len(c->option_55_data));
   o = (dhcp_option_t *) (((uword) o) + (o->length + 2));

+  /*send option 82*/
+  u8 sub2_len = vec_len(hw->hw_address);
+  o->option = 82;
+  o->length = sub2_len + 2;
+  u8 sub_option = 2;
+  clib_memcpy (o->data, &sub_option, 1);
+  clib_memcpy (o->data + 1,&sub2_len, 1);
+  clib_memcpy (o->data + 2, hw->hw_address, vec_len(hw->hw_address));
+  o = (dhcp_option_t *) (((uword) o) + (o->length +2));
+
   /* End of list */
   o->option = 0xff;
   o->length = 0;