LCOV - code coverage report
Current view: top level - libbpfilter - if.c (source / functions) Coverage Total Hit
Test: coverage.lcov Lines: 87.5 % 8 7
Test Date: 2025-11-24 12:34:34 Functions: 100.0 % 2 2
Branches: 83.3 % 6 5

             Branch data     Line data    Source code
       1                 :             : /* SPDX-License-Identifier: GPL-2.0-only */
       2                 :             : /*
       3                 :             :  * Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
       4                 :             :  */
       5                 :             : 
       6                 :             : // clang-format off
       7                 :             : // Include net/if.h before any kernel header to avoid conflicts.
       8                 :             : #include <net/if.h>
       9                 :             : // clang-format on
      10                 :             : 
      11                 :             : #include "bpfilter/if.h"
      12                 :             : 
      13                 :             : #include <errno.h>
      14                 :             : #include <limits.h>
      15                 :             : #include <sys/types.h>
      16                 :             : 
      17                 :             : #include "bpfilter/helper.h"
      18                 :             : 
      19                 :             : static char _bf_if_name[IFNAMSIZ];
      20                 :             : 
      21                 :          40 : int bf_if_index_from_name(const char *name)
      22                 :             : {
      23                 :             :     unsigned int r;
      24                 :             : 
      25                 :             :     bf_assert(name);
      26                 :             : 
      27                 :          40 :     r = if_nametoindex(name);
      28         [ +  + ]:          40 :     if (r == 0)
      29                 :             :         return -ENOENT;
      30                 :             : 
      31         [ -  + ]:          12 :     if (r > INT_MAX)
      32                 :           0 :         return -E2BIG;
      33                 :             : 
      34                 :             :     return (int)r;
      35                 :             : }
      36                 :             : 
      37                 :           4 : const char *bf_if_name_from_index(int index)
      38                 :             : {
      39         [ +  + ]:           4 :     if (!if_indextoname(index, _bf_if_name))
      40                 :           2 :         return NULL;
      41                 :             : 
      42                 :             :     return _bf_if_name;
      43                 :             : }
        

Generated by: LCOV version 2.0-1