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