LCOV - code coverage report
Current view: top level - libsystemd/sd-netlink - netlink-util.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 8 63 12.7 %
Date: 2019-08-22 15:41:25 Functions: 1 5 20.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include "sd-netlink.h"
       4             : 
       5             : #include "netlink-internal.h"
       6             : #include "netlink-util.h"
       7             : 
       8           0 : int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name) {
       9           0 :         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL;
      10             :         int r;
      11             : 
      12           0 :         assert(rtnl);
      13           0 :         assert(ifindex > 0);
      14           0 :         assert(name);
      15             : 
      16           0 :         if (!ifname_valid(name))
      17           0 :                 return -EINVAL;
      18             : 
      19           0 :         if (!*rtnl) {
      20           0 :                 r = sd_netlink_open(rtnl);
      21           0 :                 if (r < 0)
      22           0 :                         return r;
      23             :         }
      24             : 
      25           0 :         r = sd_rtnl_message_new_link(*rtnl, &message, RTM_SETLINK, ifindex);
      26           0 :         if (r < 0)
      27           0 :                 return r;
      28             : 
      29           0 :         r = sd_netlink_message_append_string(message, IFLA_IFNAME, name);
      30           0 :         if (r < 0)
      31           0 :                 return r;
      32             : 
      33           0 :         r = sd_netlink_call(*rtnl, message, 0, NULL);
      34           0 :         if (r < 0)
      35           0 :                 return r;
      36             : 
      37           0 :         return 0;
      38             : }
      39             : 
      40           0 : int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias,
      41             :                              const struct ether_addr *mac, uint32_t mtu) {
      42           0 :         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL;
      43             :         int r;
      44             : 
      45           0 :         assert(rtnl);
      46           0 :         assert(ifindex > 0);
      47             : 
      48           0 :         if (!alias && !mac && mtu == 0)
      49           0 :                 return 0;
      50             : 
      51           0 :         if (!*rtnl) {
      52           0 :                 r = sd_netlink_open(rtnl);
      53           0 :                 if (r < 0)
      54           0 :                         return r;
      55             :         }
      56             : 
      57           0 :         r = sd_rtnl_message_new_link(*rtnl, &message, RTM_SETLINK, ifindex);
      58           0 :         if (r < 0)
      59           0 :                 return r;
      60             : 
      61           0 :         if (alias) {
      62           0 :                 r = sd_netlink_message_append_string(message, IFLA_IFALIAS, alias);
      63           0 :                 if (r < 0)
      64           0 :                         return r;
      65             :         }
      66             : 
      67           0 :         if (mac) {
      68           0 :                 r = sd_netlink_message_append_ether_addr(message, IFLA_ADDRESS, mac);
      69           0 :                 if (r < 0)
      70           0 :                         return r;
      71             :         }
      72             : 
      73           0 :         if (mtu != 0) {
      74           0 :                 r = sd_netlink_message_append_u32(message, IFLA_MTU, mtu);
      75           0 :                 if (r < 0)
      76           0 :                         return r;
      77             :         }
      78             : 
      79           0 :         r = sd_netlink_call(*rtnl, message, 0, NULL);
      80           0 :         if (r < 0)
      81           0 :                 return r;
      82             : 
      83           0 :         return 0;
      84             : }
      85             : 
      86           1 : int rtnl_message_new_synthetic_error(sd_netlink *rtnl, int error, uint32_t serial, sd_netlink_message **ret) {
      87             :         struct nlmsgerr *err;
      88             :         int r;
      89             : 
      90           1 :         assert(error <= 0);
      91             : 
      92           1 :         r = message_new(rtnl, ret, NLMSG_ERROR);
      93           1 :         if (r < 0)
      94           0 :                 return r;
      95             : 
      96           1 :         (*ret)->hdr->nlmsg_seq = serial;
      97             : 
      98           1 :         err = NLMSG_DATA((*ret)->hdr);
      99             : 
     100           1 :         err->error = error;
     101             : 
     102           1 :         return 0;
     103             : }
     104             : 
     105           0 : int rtnl_log_parse_error(int r) {
     106           0 :         return log_error_errno(r, "Failed to parse netlink message: %m");
     107             : }
     108             : 
     109           0 : int rtnl_log_create_error(int r) {
     110           0 :         return log_error_errno(r, "Failed to create netlink message: %m");
     111             : }

Generated by: LCOV version 1.14