LCOV - code coverage report
Current view: top level - plugins/pppoe - pppoe_cp_node.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 75 95 78.9 %
Date: 2023-10-26 01:39:38 Functions: 8 11 72.7 %

          Line data    Source code
       1             : /*
       2             :  *------------------------------------------------------------------
       3             :  * Copyright (c) 2017 Intel and/or its affiliates.
       4             :  * Licensed under the Apache License, Version 2.0 (the "License");
       5             :  * you may not use this file except in compliance with the License.
       6             :  * You may obtain a copy of the License at:
       7             :  *
       8             :  *     http://www.apache.org/licenses/LICENSE-2.0
       9             :  *
      10             :  * Unless required by applicable law or agreed to in writing, software
      11             :  * distributed under the License is distributed on an "AS IS" BASIS,
      12             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or pemplied.
      13             :  * See the License for the specific language governing permissions and
      14             :  * lpemitations under the License.
      15             :  *------------------------------------------------------------------
      16             :  */
      17             : 
      18             : #include <vlib/vlib.h>
      19             : #include <vnet/ppp/packet.h>
      20             : #include <pppoe/pppoe.h>
      21             : 
      22             : #define foreach_pppoe_cp_next        \
      23             : _(DROP, "error-drop")                  \
      24             : _(INTERFACE, "interface-output" )      \
      25             : 
      26             : typedef enum
      27             : {
      28             : #define _(s,n) PPPOE_CP_NEXT_##s,
      29             :   foreach_pppoe_cp_next
      30             : #undef _
      31             :     PPPOE_CP_N_NEXT,
      32             : } pppoe_cp_next_t;
      33             : 
      34             : typedef struct {
      35             :   u32 next_index;
      36             :   u32 sw_if_index;
      37             :   u32 cp_if_index;
      38             :   u8 pppoe_code;
      39             :   u16 ppp_proto;
      40             :   u32 error;
      41             : } pppoe_cp_trace_t;
      42             : 
      43           4 : static u8 * format_pppoe_cp_trace (u8 * s, va_list * args)
      44             : {
      45           4 :   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
      46           4 :   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
      47           4 :   pppoe_cp_trace_t * t = va_arg (*args, pppoe_cp_trace_t *);
      48           4 :   pppoe_main_t * pem = &pppoe_main;
      49             : 
      50           4 :   if (t->sw_if_index != pem->cp_if_index)
      51             :     {
      52           4 :       s = format (s, "PPPoE dispatch from sw_if_index %d next %d error %d \n"
      53             :                   "  pppoe_code 0x%x  ppp_proto 0x%x",
      54             :                   t->sw_if_index, t->next_index, t->error,
      55           4 :                   t->pppoe_code, t->ppp_proto);
      56             :     }
      57             :   else
      58             :     {
      59           0 :       s = format (s, "PPPoE dispatch from cp_if_index %d next %d error %d \n"
      60             :                   "  pppoe_code 0x%x  ppp_proto 0x%x",
      61             :                   t->cp_if_index, t->next_index, t->error,
      62           0 :                   t->pppoe_code, t->ppp_proto);
      63             :     }
      64           4 :   return s;
      65             : }
      66             : 
      67        2316 : VLIB_NODE_FN (pppoe_cp_dispatch_node) (vlib_main_t * vm,
      68             :                     vlib_node_runtime_t * node,
      69             :                     vlib_frame_t * from_frame)
      70             : {
      71             :   u32 n_left_from, next_index, * from, * to_next;
      72          16 :   pppoe_main_t * pem = &pppoe_main;
      73          16 :   vnet_main_t * vnm = pem->vnet_main;
      74          16 :   vnet_interface_main_t * im = &vnm->interface_main;
      75          16 :   u32 pkts_decapsulated = 0;
      76          16 :   u32 thread_index = vlib_get_thread_index();
      77             :   u32 stats_sw_if_index, stats_n_packets, stats_n_bytes;
      78             :   pppoe_entry_key_t cached_key;
      79             :   pppoe_entry_result_t cached_result;
      80             : 
      81          16 :   from = vlib_frame_vector_args (from_frame);
      82          16 :   n_left_from = from_frame->n_vectors;
      83             : 
      84             :   /* Clear the one-entry cache in case session table was updated */
      85          16 :   cached_key.raw = ~0;
      86          16 :   cached_result.raw = ~0;       /* warning be gone */
      87             : 
      88          16 :   next_index = node->cached_next_index;
      89          16 :   stats_sw_if_index = node->runtime_data[0];
      90          16 :   stats_n_packets = stats_n_bytes = 0;
      91             : 
      92          32 :   while (n_left_from > 0)
      93             :     {
      94             :       u32 n_left_to_next;
      95             : 
      96          16 :       vlib_get_next_frame (vm, node, next_index,
      97             :                            to_next, n_left_to_next);
      98             : 
      99          32 :       while (n_left_from > 0 && n_left_to_next > 0)
     100             :         {
     101             :           u32 bi0;
     102             :           vlib_buffer_t * b0;
     103             :           ethernet_header_t *h0;
     104             :           pppoe_header_t * pppoe0;
     105             :           pppoe_entry_key_t key0;
     106             :           pppoe_entry_result_t result0;
     107             : 
     108             :           u32 bucket0;
     109             :           u32 next0;
     110          16 :           u32 error0 = 0;
     111          16 :           u32 rx_sw_if_index0=~0, tx_sw_if_index0=~0, len0;
     112             :           vnet_hw_interface_t *hi;
     113             :           vnet_sw_interface_t *si;
     114             : 
     115          16 :           bi0 = from[0];
     116          16 :           to_next[0] = bi0;
     117          16 :           from += 1;
     118          16 :           to_next += 1;
     119          16 :           n_left_from -= 1;
     120          16 :           n_left_to_next -= 1;
     121             : 
     122          16 :           b0 = vlib_get_buffer (vm, bi0);
     123             :           /* leaves current_data pointing at the pppoe header */
     124          16 :           pppoe0 = vlib_buffer_get_current (b0);
     125          16 :           rx_sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
     126             : 
     127          16 :           if (PREDICT_FALSE (pppoe0->ver_type != PPPOE_VER_TYPE))
     128             :             {
     129           0 :               error0 = PPPOE_ERROR_BAD_VER_TYPE;
     130           0 :               next0 = PPPOE_INPUT_NEXT_DROP;
     131           0 :               goto trace00;
     132             :             }
     133             : 
     134          16 :           vlib_buffer_reset(b0);
     135          16 :           h0 = vlib_buffer_get_current (b0);
     136             : 
     137          16 :           if(rx_sw_if_index0 == pem->cp_if_index)
     138             :             {
     139           0 :               pppoe_lookup_1 (&pem->link_table, &cached_key, &cached_result,
     140           0 :                               h0->dst_address, 0,
     141             :                               &key0, &bucket0, &result0);
     142           0 :               tx_sw_if_index0 = result0.fields.sw_if_index;
     143             : 
     144           0 :               if (PREDICT_FALSE (tx_sw_if_index0 == ~0))
     145             :                 {
     146           0 :                   error0 = PPPOE_ERROR_NO_SUCH_SESSION;
     147           0 :                   next0 = PPPOE_INPUT_NEXT_DROP;
     148           0 :                   goto trace00;
     149             :                 }
     150             : 
     151           0 :               next0 = PPPOE_CP_NEXT_INTERFACE;
     152           0 :               vnet_buffer(b0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
     153             : 
     154             :               /* set src mac address */
     155           0 :               si = vnet_get_sw_interface(vnm, tx_sw_if_index0);
     156           0 :               if( si->type == VNET_SW_INTERFACE_TYPE_SUB ) {
     157           0 :                 si = vnet_get_sw_interface(vnm, si->sup_sw_if_index);
     158             :               }
     159           0 :               hi = vnet_get_hw_interface (vnm, si->hw_if_index);
     160           0 :               clib_memcpy_fast (vlib_buffer_get_current (b0)+6, hi->hw_address, 6);
     161             :             }
     162             :           else
     163             :             {
     164          16 :               pppoe_lookup_1 (&pem->link_table, &cached_key, &cached_result,
     165          16 :                               h0->src_address, 0,
     166             :                               &key0, &bucket0, &result0);
     167          16 :               tx_sw_if_index0 = result0.fields.sw_if_index;
     168             : 
     169             :               /* learn client session */
     170          16 :               pppoe_learn_process (&pem->link_table, rx_sw_if_index0,
     171             :                                    &key0, &cached_key,
     172             :                                    &bucket0, &result0);
     173             : 
     174          16 :               next0 = PPPOE_CP_NEXT_INTERFACE;
     175          16 :               vnet_buffer(b0)->sw_if_index[VLIB_TX] = pem->cp_if_index;
     176             :             }
     177             : 
     178          16 :           len0 = vlib_buffer_length_in_chain (vm, b0);
     179             : 
     180          16 :           pkts_decapsulated ++;
     181          16 :           stats_n_packets += 1;
     182          16 :           stats_n_bytes += len0;
     183             : 
     184             :           /* Batch stats increment on the same pppoe session so counter
     185             :              is not incremented per packet */
     186          16 :           if (PREDICT_FALSE (rx_sw_if_index0 != stats_sw_if_index))
     187             :             {
     188           4 :               stats_n_packets -= 1;
     189           4 :               stats_n_bytes -= len0;
     190           4 :               if (stats_n_packets)
     191           0 :                 vlib_increment_combined_counter
     192             :                   (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
     193             :                    thread_index, stats_sw_if_index,
     194             :                    stats_n_packets, stats_n_bytes);
     195           4 :               stats_n_packets = 1;
     196           4 :               stats_n_bytes = len0;
     197           4 :               stats_sw_if_index = rx_sw_if_index0;
     198             :             }
     199             :         
     200          12 :         trace00:  
     201          16 :           b0->error = error0 ? node->errors[error0] : 0;
     202             : 
     203          16 :           if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
     204             :             {
     205             :               pppoe_cp_trace_t *tr
     206          16 :                 = vlib_add_trace (vm, node, b0, sizeof (*tr));
     207          16 :               tr->next_index = next0;
     208          16 :               tr->error = error0;
     209          16 :               tr->sw_if_index = tx_sw_if_index0;
     210          16 :               tr->cp_if_index = pem->cp_if_index;
     211          16 :               tr->pppoe_code = pppoe0->code;
     212          16 :               tr->ppp_proto = clib_net_to_host_u16(pppoe0->ppp_proto);
     213             :             }
     214          16 :           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
     215             :                                            to_next, n_left_to_next,
     216             :                                            bi0, next0);
     217             :         }
     218             : 
     219          16 :       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
     220             :     }
     221             :   /* Do we still need this now that session tx stats is kept? */
     222          16 :   vlib_node_increment_counter (vm, pppoe_input_node.index,
     223             :                                PPPOE_ERROR_DECAPSULATED,
     224             :                                pkts_decapsulated);
     225             : 
     226             :   /* Increment any remaining batch stats */
     227          16 :   if (stats_n_packets)
     228             :     {
     229          16 :       vlib_increment_combined_counter
     230             :         (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
     231             :          thread_index, stats_sw_if_index, stats_n_packets, stats_n_bytes);
     232          16 :       node->runtime_data[0] = stats_sw_if_index;
     233             :     }
     234             : 
     235          16 :   return from_frame->n_vectors;
     236             : }
     237             : 
     238       45528 : VLIB_REGISTER_NODE (pppoe_cp_dispatch_node) = {
     239             :   .name = "pppoe-cp-dispatch",
     240             :   /* Takes a vector of packets. */
     241             :   .vector_size = sizeof (u32),
     242             : 
     243             :   .n_errors = PPPOE_N_ERROR,
     244             :   .error_strings = pppoe_error_strings,
     245             : 
     246             :   .n_next_nodes = PPPOE_CP_N_NEXT,
     247             :   .next_nodes = {
     248             : #define _(s,n) [PPPOE_CP_NEXT_##s] = n,
     249             :     foreach_pppoe_cp_next
     250             : #undef _
     251             :   },
     252             : 
     253             :   .format_trace = format_pppoe_cp_trace,
     254             : };
     255             : 

Generated by: LCOV version 1.14