LCOV - code coverage report
Current view: top level - network/netdev - macvlan.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 1 23 4.3 %
Date: 2019-08-22 15:41:25 Functions: 2 5 40.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include <net/if.h>
       4             : 
       5             : #include "conf-parser.h"
       6             : #include "netdev/macvlan.h"
       7             : #include "string-table.h"
       8             : 
       9             : static const char* const macvlan_mode_table[_NETDEV_MACVLAN_MODE_MAX] = {
      10             :         [NETDEV_MACVLAN_MODE_PRIVATE] = "private",
      11             :         [NETDEV_MACVLAN_MODE_VEPA] = "vepa",
      12             :         [NETDEV_MACVLAN_MODE_BRIDGE] = "bridge",
      13             :         [NETDEV_MACVLAN_MODE_PASSTHRU] = "passthru",
      14             : };
      15             : 
      16          22 : DEFINE_STRING_TABLE_LOOKUP(macvlan_mode, MacVlanMode);
      17           0 : DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode, "Failed to parse macvlan mode");
      18             : 
      19           0 : static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
      20             :         MacVlan *m;
      21             :         int r;
      22             : 
      23           0 :         assert(netdev);
      24           0 :         assert(link);
      25           0 :         assert(netdev->ifname);
      26             : 
      27           0 :         if (netdev->kind == NETDEV_KIND_MACVLAN)
      28           0 :                 m = MACVLAN(netdev);
      29             :         else
      30           0 :                 m = MACVTAP(netdev);
      31             : 
      32           0 :         assert(m);
      33             : 
      34           0 :         if (m->mode != _NETDEV_MACVLAN_MODE_INVALID) {
      35           0 :                 r = sd_netlink_message_append_u32(req, IFLA_MACVLAN_MODE, m->mode);
      36           0 :                 if (r < 0)
      37           0 :                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACVLAN_MODE attribute: %m");
      38             :         }
      39             : 
      40           0 :         return 0;
      41             : }
      42             : 
      43           0 : static void macvlan_init(NetDev *n) {
      44             :         MacVlan *m;
      45             : 
      46           0 :         assert(n);
      47             : 
      48           0 :         if (n->kind == NETDEV_KIND_MACVLAN)
      49           0 :                 m = MACVLAN(n);
      50             :         else
      51           0 :                 m = MACVTAP(n);
      52             : 
      53           0 :         assert(m);
      54             : 
      55           0 :         m->mode = _NETDEV_MACVLAN_MODE_INVALID;
      56           0 : }
      57             : 
      58             : const NetDevVTable macvtap_vtable = {
      59             :         .object_size = sizeof(MacVlan),
      60             :         .init = macvlan_init,
      61             :         .sections = "Match\0NetDev\0MACVTAP\0",
      62             :         .fill_message_create = netdev_macvlan_fill_message_create,
      63             :         .create_type = NETDEV_CREATE_STACKED,
      64             :         .generate_mac = true,
      65             : };
      66             : 
      67             : const NetDevVTable macvlan_vtable = {
      68             :         .object_size = sizeof(MacVlan),
      69             :         .init = macvlan_init,
      70             :         .sections = "Match\0NetDev\0MACVLAN\0",
      71             :         .fill_message_create = netdev_macvlan_fill_message_create,
      72             :         .create_type = NETDEV_CREATE_STACKED,
      73             :         .generate_mac = true,
      74             : };

Generated by: LCOV version 1.14