LCOV - code coverage report
Current view: top level - plugins/linux-cp - lcp.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 16 55 29.1 %
Date: 2023-07-05 22:20:52 Functions: 5 11 45.5 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2020 Cisco and/or its affiliates.
       3             :  * Licensed under the Apache License, Version 2.0 (the "License");
       4             :  * you may not use this file except in compliance with the License.
       5             :  * You may obtain a copy of the License at:
       6             :  *
       7             :  *     http://www.apache.org/licenses/LICENSE-2.0
       8             :  *
       9             :  * Unless required by applicable law or agreed to in writing, software
      10             :  * distributed under the License is distributed on an "AS IS" BASIS,
      11             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             :  * See the License for the specific language governing permissions and
      13             :  * limitations under the License.
      14             :  */
      15             : 
      16             : #include <sched.h>
      17             : #include <fcntl.h>
      18             : #include <ctype.h>
      19             : #include <sys/socket.h>
      20             : #include <net/if.h>
      21             : 
      22             : #include <plugins/linux-cp/lcp.h>
      23             : #include <plugins/linux-cp/lcp_interface.h>
      24             : 
      25             : lcp_main_t lcp_main;
      26             : 
      27             : u8 *
      28           3 : lcp_get_default_ns (void)
      29             : {
      30           3 :   lcp_main_t *lcpm = &lcp_main;
      31             : 
      32           3 :   if (!lcpm->default_namespace || lcpm->default_namespace[0] == 0)
      33           3 :     return NULL;
      34             : 
      35           0 :   return lcpm->default_namespace;
      36             : }
      37             : 
      38             : int
      39           0 : lcp_get_default_ns_fd (void)
      40             : {
      41           0 :   lcp_main_t *lcpm = &lcp_main;
      42             : 
      43           0 :   return lcpm->default_ns_fd;
      44             : }
      45             : 
      46             : /*
      47             :  * ns is expected to be or look like a NUL-terminated C string.
      48             :  */
      49             : int
      50           0 : lcp_set_default_ns (u8 *ns)
      51             : {
      52           0 :   lcp_main_t *lcpm = &lcp_main;
      53             :   char *p;
      54             :   int len;
      55             :   u8 *s;
      56             : 
      57           0 :   p = (char *) ns;
      58           0 :   len = clib_strnlen (p, LCP_NS_LEN);
      59           0 :   if (len >= LCP_NS_LEN)
      60           0 :     return -1;
      61             : 
      62           0 :   if (!p || *p == 0)
      63             :     {
      64           0 :       lcpm->default_namespace = NULL;
      65           0 :       if (lcpm->default_ns_fd > 0)
      66           0 :         close (lcpm->default_ns_fd);
      67           0 :       lcpm->default_ns_fd = 0;
      68           0 :       return 0;
      69             :     }
      70             : 
      71           0 :   vec_validate_init_c_string (lcpm->default_namespace, p,
      72             :                               clib_strnlen (p, LCP_NS_LEN));
      73           0 :   s = format (0, "/var/run/netns/%s%c", (char *) lcpm->default_namespace, 0);
      74           0 :   lcpm->default_ns_fd = open ((char *) s, O_RDONLY);
      75           0 :   vec_free (s);
      76             : 
      77           0 :   return 0;
      78             : }
      79             : 
      80             : void
      81           0 : lcp_set_sync (u8 is_auto)
      82             : {
      83           0 :   lcp_main_t *lcpm = &lcp_main;
      84             : 
      85           0 :   lcpm->lcp_sync = (is_auto != 0);
      86             : 
      87             :   // If we set to 'on', do a one-off sync of LCP interfaces
      88           0 :   if (is_auto)
      89           0 :     lcp_itf_pair_sync_state_all ();
      90           0 : }
      91             : 
      92             : int
      93          78 : lcp_sync (void)
      94             : {
      95          78 :   lcp_main_t *lcpm = &lcp_main;
      96             : 
      97          78 :   return lcpm->lcp_sync;
      98             : }
      99             : 
     100             : void
     101           0 : lcp_set_auto_subint (u8 is_auto)
     102             : {
     103           0 :   lcp_main_t *lcpm = &lcp_main;
     104             : 
     105           0 :   lcpm->lcp_auto_subint = (is_auto != 0);
     106           0 : }
     107             : 
     108             : int
     109          22 : lcp_auto_subint (void)
     110             : {
     111          22 :   lcp_main_t *lcpm = &lcp_main;
     112             : 
     113          22 :   return lcpm->lcp_auto_subint;
     114             : }
     115             : 
     116             : void
     117           0 : lcp_set_del_static_on_link_down (u8 is_del)
     118             : {
     119           0 :   lcp_main_t *lcpm = &lcp_main;
     120             : 
     121           0 :   lcpm->del_static_on_link_down = (is_del != 0);
     122           0 : }
     123             : 
     124             : u8
     125           3 : lcp_get_del_static_on_link_down (void)
     126             : {
     127           3 :   lcp_main_t *lcpm = &lcp_main;
     128             : 
     129           3 :   return lcpm->del_static_on_link_down;
     130             : }
     131             : 
     132             : void
     133           0 : lcp_set_del_dynamic_on_link_down (u8 is_del)
     134             : {
     135           0 :   lcp_main_t *lcpm = &lcp_main;
     136             : 
     137           0 :   lcpm->del_dynamic_on_link_down = (is_del != 0);
     138           0 : }
     139             : 
     140             : u8
     141           3 : lcp_get_del_dynamic_on_link_down (void)
     142             : {
     143           3 :   lcp_main_t *lcpm = &lcp_main;
     144             : 
     145           3 :   return lcpm->del_dynamic_on_link_down;
     146             : }
     147             : 
     148             : /*
     149             :  * fd.io coding-style-patch-verification: ON
     150             :  *
     151             :  * Local Variables:
     152             :  * eval: (c-set-style "gnu")
     153             :  * End:
     154             :  */

Generated by: LCOV version 1.14