LCOV - code coverage report
Current view: top level - network/netdev - veth.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 0 42 0.0 %
Date: 2019-08-22 15:41:25 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include <errno.h>
       4             : #include <net/if.h>
       5             : #include <linux/veth.h>
       6             : 
       7             : #include "sd-netlink.h"
       8             : 
       9             : #include "netdev/veth.h"
      10             : 
      11           0 : static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
      12             :         Veth *v;
      13             :         int r;
      14             : 
      15           0 :         assert(netdev);
      16           0 :         assert(!link);
      17           0 :         assert(m);
      18             : 
      19           0 :         v = VETH(netdev);
      20             : 
      21           0 :         assert(v);
      22             : 
      23           0 :         r = sd_netlink_message_open_container(m, VETH_INFO_PEER);
      24           0 :         if (r < 0)
      25           0 :                 return log_netdev_error_errno(netdev, r, "Could not append VETH_INFO_PEER attribute: %m");
      26             : 
      27           0 :         if (v->ifname_peer) {
      28           0 :                 r = sd_netlink_message_append_string(m, IFLA_IFNAME, v->ifname_peer);
      29           0 :                 if (r < 0)
      30           0 :                         return log_error_errno(r, "Failed to add netlink interface name: %m");
      31             :         }
      32             : 
      33           0 :         if (v->mac_peer) {
      34           0 :                 r = sd_netlink_message_append_ether_addr(m, IFLA_ADDRESS, v->mac_peer);
      35           0 :                 if (r < 0)
      36           0 :                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_ADDRESS attribute: %m");
      37             :         }
      38             : 
      39           0 :         r = sd_netlink_message_close_container(m);
      40           0 :         if (r < 0)
      41           0 :                 return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m");
      42             : 
      43           0 :         return r;
      44             : }
      45             : 
      46           0 : static int netdev_veth_verify(NetDev *netdev, const char *filename) {
      47             :         Veth *v;
      48             :         int r;
      49             : 
      50           0 :         assert(netdev);
      51           0 :         assert(filename);
      52             : 
      53           0 :         v = VETH(netdev);
      54             : 
      55           0 :         assert(v);
      56             : 
      57           0 :         if (!v->ifname_peer) {
      58           0 :                 log_warning("Veth NetDev without peer name configured in %s. Ignoring",
      59             :                             filename);
      60           0 :                 return -EINVAL;
      61             :         }
      62             : 
      63           0 :         if (!v->mac_peer) {
      64           0 :                 r = netdev_get_mac(v->ifname_peer, &v->mac_peer);
      65           0 :                 if (r < 0) {
      66           0 :                         log_warning("Failed to generate predictable MAC address for %s. Ignoring",
      67             :                                   v->ifname_peer);
      68           0 :                         return -EINVAL;
      69             :                 }
      70             :         }
      71             : 
      72           0 :         return 0;
      73             : }
      74             : 
      75           0 : static void veth_done(NetDev *n) {
      76             :         Veth *v;
      77             : 
      78           0 :         assert(n);
      79             : 
      80           0 :         v = VETH(n);
      81             : 
      82           0 :         assert(v);
      83             : 
      84           0 :         free(v->ifname_peer);
      85           0 :         free(v->mac_peer);
      86           0 : }
      87             : 
      88             : const NetDevVTable veth_vtable = {
      89             :         .object_size = sizeof(Veth),
      90             :         .sections = "Match\0NetDev\0Peer\0",
      91             :         .done = veth_done,
      92             :         .fill_message_create = netdev_veth_fill_message_create,
      93             :         .create_type = NETDEV_CREATE_INDEPENDENT,
      94             :         .config_verify = netdev_veth_verify,
      95             :         .generate_mac = true,
      96             : };

Generated by: LCOV version 1.14