LCOV - code coverage report
Current view: top level - network - networkd-network-bus.c (source / functions) Hit Total Coverage
Test: systemd test coverage Lines: 0 66 0.0 %
Date: 2015-07-29 18:47:03 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
       2             : 
       3             : /***
       4             :   This file is part of systemd.
       5             : 
       6             :   Copyright 2015 Tom Gundersen
       7             : 
       8             :   systemd is free software; you can redistribute it and/or modify it
       9             :   under the terms of the GNU Lesser General Public License as published by
      10             :   the Free Software Foundation; either version 2.1 of the License, or
      11             :   (at your option) any later version.
      12             : 
      13             :   systemd is distributed in the hope that it will be useful, but
      14             :   WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      16             :   Lesser General Public License for more details.
      17             : 
      18             :   You should have received a copy of the GNU Lesser General Public License
      19             :   along with systemd; If not, see <http://www.gnu.org/licenses/>.
      20             : ***/
      21             : 
      22             : #include "strv.h"
      23             : 
      24             : #include "networkd.h"
      25             : 
      26           0 : static int property_get_ether_addrs(
      27             :                 sd_bus *bus,
      28             :                 const char *path,
      29             :                 const char *interface,
      30             :                 const char *property,
      31             :                 sd_bus_message *reply,
      32             :                 void *userdata,
      33             :                 sd_bus_error *error) {
      34             : 
      35           0 :         Network *n = userdata;
      36           0 :         const char *ether = NULL;
      37             :         int r;
      38             : 
      39           0 :         assert(bus);
      40           0 :         assert(reply);
      41           0 :         assert(n);
      42             : 
      43           0 :         if (n->match_mac)
      44           0 :                 ether = ether_ntoa(n->match_mac);
      45             : 
      46           0 :         r = sd_bus_message_open_container(reply, 'a', "s");
      47           0 :         if (r < 0)
      48           0 :                 return r;
      49             : 
      50           0 :         if (ether) {
      51           0 :                 r = sd_bus_message_append(reply, "s", strempty(ether));
      52           0 :                 if (r < 0)
      53           0 :                         return r;
      54             :         }
      55             : 
      56           0 :         return sd_bus_message_close_container(reply);
      57             : }
      58             : 
      59             : const sd_bus_vtable network_vtable[] = {
      60             :         SD_BUS_VTABLE_START(0),
      61             : 
      62             :         SD_BUS_PROPERTY("Description", "s", NULL, offsetof(Network, description), SD_BUS_VTABLE_PROPERTY_CONST),
      63             :         SD_BUS_PROPERTY("SourcePath", "s", NULL, offsetof(Network, filename), SD_BUS_VTABLE_PROPERTY_CONST),
      64             :         SD_BUS_PROPERTY("MatchMAC", "as", property_get_ether_addrs, offsetof(Network, match_mac), SD_BUS_VTABLE_PROPERTY_CONST),
      65             :         SD_BUS_PROPERTY("MatchPath", "as", NULL, offsetof(Network, match_path), SD_BUS_VTABLE_PROPERTY_CONST),
      66             :         SD_BUS_PROPERTY("MatchDriver", "as", NULL, offsetof(Network, match_driver), SD_BUS_VTABLE_PROPERTY_CONST),
      67             :         SD_BUS_PROPERTY("MatchType", "as", NULL, offsetof(Network, match_type), SD_BUS_VTABLE_PROPERTY_CONST),
      68             :         SD_BUS_PROPERTY("MatchName", "as", NULL, offsetof(Network, match_name), SD_BUS_VTABLE_PROPERTY_CONST),
      69             : 
      70             :         SD_BUS_VTABLE_END
      71             : };
      72             : 
      73           0 : static char *network_bus_path(Network *network) {
      74           0 :         _cleanup_free_ char *name = NULL;
      75             :         char *networkname, *d, *path;
      76             :         int r;
      77             : 
      78           0 :         assert(network);
      79           0 :         assert(network->filename);
      80             : 
      81           0 :         name = strdup(network->filename);
      82           0 :         if (!name)
      83           0 :                 return NULL;
      84             : 
      85           0 :         networkname = basename(name);
      86             : 
      87           0 :         d = strrchr(networkname, '.');
      88           0 :         if (!d)
      89           0 :                 return NULL;
      90             : 
      91           0 :         assert(streq(d, ".network"));
      92             : 
      93           0 :         *d = '\0';
      94             : 
      95           0 :         r = sd_bus_path_encode("/org/freedesktop/network1/network", networkname, &path);
      96           0 :         if (r < 0)
      97           0 :                 return NULL;
      98             : 
      99           0 :         return path;
     100             : }
     101             : 
     102           0 : int network_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
     103           0 :         _cleanup_strv_free_ char **l = NULL;
     104           0 :         Manager *m = userdata;
     105             :         Network *network;
     106             :         int r;
     107             : 
     108           0 :         assert(bus);
     109           0 :         assert(path);
     110           0 :         assert(m);
     111           0 :         assert(nodes);
     112             : 
     113           0 :         LIST_FOREACH(networks, network, m->networks) {
     114             :                 char *p;
     115             : 
     116           0 :                 p = network_bus_path(network);
     117           0 :                 if (!p)
     118           0 :                         return -ENOMEM;
     119             : 
     120           0 :                 r = strv_consume(&l, p);
     121           0 :                 if (r < 0)
     122           0 :                         return r;
     123             :         }
     124             : 
     125           0 :         *nodes = l;
     126           0 :         l = NULL;
     127             : 
     128           0 :         return 1;
     129             : }
     130             : 
     131           0 : int network_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
     132           0 :         Manager *m = userdata;
     133             :         Network *network;
     134           0 :         _cleanup_free_ char *name = NULL;
     135             :         int r;
     136             : 
     137           0 :         assert(bus);
     138           0 :         assert(path);
     139           0 :         assert(interface);
     140           0 :         assert(m);
     141           0 :         assert(found);
     142             : 
     143           0 :         r = sd_bus_path_decode(path, "/org/freedesktop/network1/network", &name);
     144           0 :         if (r < 0)
     145           0 :                 return 0;
     146             : 
     147           0 :         r = network_get_by_name(m, name, &network);
     148           0 :         if (r < 0)
     149           0 :                 return 0;
     150             : 
     151           0 :         *found = network;
     152             : 
     153           0 :         return 1;
     154             : }

Generated by: LCOV version 1.11