LCOV - code coverage report
Current view: top level - network - networkd-netdev-vxlan.c (source / functions) Hit Total Coverage
Test: systemd test coverage Lines: 0 89 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 2014 Susant Sahani <susant@redhat.com>
       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 <net/if.h>
      23             : 
      24             : #include "sd-netlink.h"
      25             : #include "networkd-netdev-vxlan.h"
      26             : #include "networkd-link.h"
      27             : #include "conf-parser.h"
      28             : #include "missing.h"
      29             : 
      30           0 : static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
      31           0 :         VxLan *v = VXLAN(netdev);
      32             :         int r;
      33             : 
      34           0 :         assert(netdev);
      35           0 :         assert(v);
      36           0 :         assert(link);
      37           0 :         assert(m);
      38             : 
      39             : 
      40           0 :         if (v->id <= VXLAN_VID_MAX) {
      41           0 :                 r = sd_netlink_message_append_u32(m, IFLA_VXLAN_ID, v->id);
      42           0 :                 if (r < 0)
      43           0 :                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_ID attribute: %m");
      44             :         }
      45             : 
      46           0 :         r = sd_netlink_message_append_in_addr(m, IFLA_VXLAN_GROUP, &v->group.in);
      47           0 :         if (r < 0)
      48           0 :                 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_GROUP attribute: %m");
      49             : 
      50           0 :         r = sd_netlink_message_append_u32(m, IFLA_VXLAN_LINK, link->ifindex);
      51           0 :         if (r < 0)
      52           0 :                 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LINK attribute: %m");
      53             : 
      54           0 :         if(v->ttl) {
      55           0 :                 r = sd_netlink_message_append_u8(m, IFLA_VXLAN_TTL, v->ttl);
      56           0 :                 if (r < 0)
      57           0 :                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_TTL attribute: %m");
      58             :         }
      59             : 
      60           0 :         if(v->tos) {
      61           0 :                 r = sd_netlink_message_append_u8(m, IFLA_VXLAN_TOS, v->tos);
      62           0 :                 if (r < 0)
      63           0 :                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_TOS attribute: %m");
      64             :         }
      65             : 
      66           0 :         r = sd_netlink_message_append_u8(m, IFLA_VXLAN_LEARNING, v->learning);
      67           0 :         if (r < 0)
      68           0 :                 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LEARNING attribute: %m");
      69             : 
      70           0 :         r = sd_netlink_message_append_u8(m, IFLA_VXLAN_RSC, v->route_short_circuit);
      71           0 :         if (r < 0)
      72           0 :                 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_RSC attribute: %m");
      73             : 
      74           0 :         r = sd_netlink_message_append_u8(m, IFLA_VXLAN_PROXY, v->arp_proxy);
      75           0 :         if (r < 0)
      76           0 :                 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_PROXY attribute: %m");
      77             : 
      78           0 :         r = sd_netlink_message_append_u8(m, IFLA_VXLAN_L2MISS, v->l2miss);
      79           0 :         if (r < 0)
      80           0 :                 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_L2MISS attribute: %m");
      81             : 
      82           0 :         r = sd_netlink_message_append_u8(m, IFLA_VXLAN_L3MISS, v->l3miss);
      83           0 :         if (r < 0)
      84           0 :                 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_L3MISS attribute: %m");
      85             : 
      86           0 :         if(v->fdb_ageing) {
      87           0 :                 r = sd_netlink_message_append_u32(m, IFLA_VXLAN_AGEING, v->fdb_ageing / USEC_PER_SEC);
      88           0 :                 if (r < 0)
      89           0 :                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_AGEING attribute: %m");
      90             :         }
      91             : 
      92           0 :         r = sd_netlink_message_append_u8(m, IFLA_VXLAN_UDP_CSUM, v->udpcsum);
      93           0 :         if (r < 0)
      94           0 :                 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_CSUM attribute: %m");
      95             : 
      96           0 :         r = sd_netlink_message_append_u8(m, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, v->udp6zerocsumtx);
      97           0 :         if (r < 0)
      98           0 :                 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_TX attribute: %m");
      99             : 
     100           0 :         r = sd_netlink_message_append_u8(m, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, v->udp6zerocsumrx);
     101           0 :         if (r < 0)
     102           0 :                 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_RX attribute: %m");
     103             : 
     104           0 :         return r;
     105             : }
     106             : 
     107           0 : int config_parse_vxlan_group_address(const char *unit,
     108             :                                      const char *filename,
     109             :                                      unsigned line,
     110             :                                      const char *section,
     111             :                                      unsigned section_line,
     112             :                                      const char *lvalue,
     113             :                                      int ltype,
     114             :                                      const char *rvalue,
     115             :                                      void *data,
     116             :                                      void *userdata) {
     117           0 :         VxLan *v = userdata;
     118           0 :         union in_addr_union *addr = data, buffer;
     119             :         int r, f;
     120             : 
     121           0 :         assert(filename);
     122           0 :         assert(lvalue);
     123           0 :         assert(rvalue);
     124           0 :         assert(data);
     125             : 
     126           0 :         r = in_addr_from_string_auto(rvalue, &f, &buffer);
     127           0 :         if (r < 0) {
     128           0 :                 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
     129             :                            "vxlan multicast group address is invalid, ignoring assignment: %s", rvalue);
     130           0 :                 return 0;
     131             :         }
     132             : 
     133           0 :         if(v->family != AF_UNSPEC && v->family != f) {
     134           0 :                 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
     135             :                            "vxlan multicast group incompatible, ignoring assignment: %s", rvalue);
     136           0 :                 return 0;
     137             :         }
     138             : 
     139           0 :         v->family = f;
     140           0 :         *addr = buffer;
     141             : 
     142           0 :         return 0;
     143             : }
     144             : 
     145           0 : static int netdev_vxlan_verify(NetDev *netdev, const char *filename) {
     146           0 :         VxLan *v = VXLAN(netdev);
     147             : 
     148           0 :         assert(netdev);
     149           0 :         assert(v);
     150           0 :         assert(filename);
     151             : 
     152           0 :         if (v->id > VXLAN_VID_MAX) {
     153           0 :                 log_warning("VXLAN without valid Id configured in %s. Ignoring", filename);
     154           0 :                 return -EINVAL;
     155             :         }
     156             : 
     157           0 :         return 0;
     158             : }
     159             : 
     160           0 : static void vxlan_init(NetDev *netdev) {
     161           0 :         VxLan *v = VXLAN(netdev);
     162             : 
     163           0 :         assert(netdev);
     164           0 :         assert(v);
     165             : 
     166           0 :         v->id = VXLAN_VID_MAX + 1;
     167           0 :         v->learning = true;
     168           0 :         v->udpcsum = false;
     169           0 :         v->udp6zerocsumtx = false;
     170           0 :         v->udp6zerocsumrx = false;
     171           0 : }
     172             : 
     173             : const NetDevVTable vxlan_vtable = {
     174             :         .object_size = sizeof(VxLan),
     175             :         .init = vxlan_init,
     176             :         .sections = "Match\0NetDev\0VXLAN\0",
     177             :         .fill_message_create = netdev_vxlan_fill_message_create,
     178             :         .create_type = NETDEV_CREATE_STACKED,
     179             :         .config_verify = netdev_vxlan_verify,
     180             : };

Generated by: LCOV version 1.11