2014-06-16 10:24:33 +04:00
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd .
2015-07-29 11:35:34 +03:00
Copyright 2014 Susant Sahani
2014-06-16 10:24:33 +04:00
systemd is free software ; you can redistribute it and / or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation ; either version 2.1 of the License , or
( at your option ) any later version .
systemd is distributed in the hope that it will be useful , but
WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with systemd ; If not , see < http : //www.gnu.org/licenses/>.
* * */
# include <net/if.h>
2015-06-12 17:31:33 +03:00
# include "sd-netlink.h"
2014-07-06 16:07:34 +04:00
# include "networkd-netdev-vxlan.h"
2014-08-06 14:50:53 +04:00
# include "networkd-link.h"
2014-11-15 05:54:59 +03:00
# include "conf-parser.h"
2014-06-21 03:45:45 +04:00
# include "missing.h"
2014-06-16 10:24:33 +04:00
2015-06-12 17:31:33 +03:00
static int netdev_vxlan_fill_message_create ( NetDev * netdev , Link * link , sd_netlink_message * m ) {
2014-07-16 15:17:10 +04:00
VxLan * v = VXLAN ( netdev ) ;
2014-06-16 10:24:33 +04:00
int r ;
2014-07-06 16:07:34 +04:00
assert ( netdev ) ;
2014-07-16 15:17:10 +04:00
assert ( v ) ;
2014-06-16 10:24:33 +04:00
assert ( link ) ;
assert ( m ) ;
2014-07-16 15:17:10 +04:00
if ( v - > id < = VXLAN_VID_MAX ) {
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u32 ( m , IFLA_VXLAN_ID , v - > id ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_ID attribute: %m " ) ;
2014-06-16 10:24:33 +04:00
}
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_in_addr ( m , IFLA_VXLAN_GROUP , & v - > group . in ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_GROUP attribute: %m " ) ;
2014-06-16 10:24:33 +04:00
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u32 ( m , IFLA_VXLAN_LINK , link - > ifindex ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_LINK attribute: %m " ) ;
2014-06-16 10:24:33 +04:00
2014-07-16 15:17:10 +04:00
if ( v - > ttl ) {
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u8 ( m , IFLA_VXLAN_TTL , v - > ttl ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_TTL attribute: %m " ) ;
2014-06-16 10:24:33 +04:00
}
2014-07-16 15:17:10 +04:00
if ( v - > tos ) {
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u8 ( m , IFLA_VXLAN_TOS , v - > tos ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_TOS attribute: %m " ) ;
2014-06-16 10:24:33 +04:00
}
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u8 ( m , IFLA_VXLAN_LEARNING , v - > learning ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_LEARNING attribute: %m " ) ;
2014-06-16 10:24:33 +04:00
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u8 ( m , IFLA_VXLAN_RSC , v - > route_short_circuit ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_RSC attribute: %m " ) ;
2014-11-15 05:54:59 +03:00
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u8 ( m , IFLA_VXLAN_PROXY , v - > arp_proxy ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_PROXY attribute: %m " ) ;
2014-11-15 05:54:59 +03:00
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u8 ( m , IFLA_VXLAN_L2MISS , v - > l2miss ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_L2MISS attribute: %m " ) ;
2014-11-15 05:54:59 +03:00
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u8 ( m , IFLA_VXLAN_L3MISS , v - > l3miss ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_L3MISS attribute: %m " ) ;
2014-11-15 05:54:59 +03:00
if ( v - > fdb_ageing ) {
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u32 ( m , IFLA_VXLAN_AGEING , v - > fdb_ageing / USEC_PER_SEC ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_AGEING attribute: %m " ) ;
2014-11-15 05:54:59 +03:00
}
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u8 ( m , IFLA_VXLAN_UDP_CSUM , v - > udpcsum ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_UDP_CSUM attribute: %m " ) ;
2015-03-05 19:32:47 +03:00
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u8 ( m , IFLA_VXLAN_UDP_ZERO_CSUM6_TX , v - > udp6zerocsumtx ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_TX attribute: %m " ) ;
2015-03-05 19:32:47 +03:00
2015-06-12 17:31:33 +03:00
r = sd_netlink_message_append_u8 ( m , IFLA_VXLAN_UDP_ZERO_CSUM6_RX , v - > udp6zerocsumrx ) ;
2015-06-10 09:25:54 +03:00
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_RX attribute: %m " ) ;
2015-03-05 19:32:47 +03:00
2015-07-29 11:35:34 +03:00
if ( v - > group_policy ) {
r = sd_netlink_message_append_flag ( m , IFLA_VXLAN_GBP ) ;
if ( r < 0 )
return log_netdev_error_errno ( netdev , r , " Could not append IFLA_VXLAN_GBP attribute: %m " ) ;
}
2014-06-16 10:24:33 +04:00
return r ;
}
2014-11-15 05:54:59 +03:00
int config_parse_vxlan_group_address ( const char * unit ,
const char * filename ,
unsigned line ,
const char * section ,
unsigned section_line ,
const char * lvalue ,
int ltype ,
const char * rvalue ,
void * data ,
void * userdata ) {
VxLan * v = userdata ;
union in_addr_union * addr = data , buffer ;
int r , f ;
assert ( filename ) ;
assert ( lvalue ) ;
assert ( rvalue ) ;
assert ( data ) ;
r = in_addr_from_string_auto ( rvalue , & f , & buffer ) ;
if ( r < 0 ) {
log_syntax ( unit , LOG_ERR , filename , line , EINVAL ,
" vxlan multicast group address is invalid, ignoring assignment: %s " , rvalue ) ;
return 0 ;
}
if ( v - > family ! = AF_UNSPEC & & v - > family ! = f ) {
log_syntax ( unit , LOG_ERR , filename , line , EINVAL ,
" vxlan multicast group incompatible, ignoring assignment: %s " , rvalue ) ;
return 0 ;
}
v - > family = f ;
* addr = buffer ;
return 0 ;
}
2014-07-06 16:07:34 +04:00
static int netdev_vxlan_verify ( NetDev * netdev , const char * filename ) {
2014-07-16 15:17:10 +04:00
VxLan * v = VXLAN ( netdev ) ;
2014-06-16 10:24:33 +04:00
assert ( netdev ) ;
2014-07-16 15:17:10 +04:00
assert ( v ) ;
2014-07-06 16:07:34 +04:00
assert ( filename ) ;
2014-06-16 10:24:33 +04:00
2014-07-16 15:17:10 +04:00
if ( v - > id > VXLAN_VID_MAX ) {
2014-07-06 16:07:34 +04:00
log_warning ( " VXLAN without valid Id configured in %s. Ignoring " , filename ) ;
return - EINVAL ;
2014-06-16 10:24:33 +04:00
}
return 0 ;
}
2014-07-06 16:07:34 +04:00
2014-07-16 15:17:10 +04:00
static void vxlan_init ( NetDev * netdev ) {
VxLan * v = VXLAN ( netdev ) ;
assert ( netdev ) ;
assert ( v ) ;
v - > id = VXLAN_VID_MAX + 1 ;
v - > learning = true ;
2015-03-05 19:32:47 +03:00
v - > udpcsum = false ;
v - > udp6zerocsumtx = false ;
v - > udp6zerocsumrx = false ;
2014-07-16 15:17:10 +04:00
}
2014-07-06 16:07:34 +04:00
const NetDevVTable vxlan_vtable = {
2014-07-16 15:17:10 +04:00
. object_size = sizeof ( VxLan ) ,
. init = vxlan_init ,
. sections = " Match \0 NetDev \0 VXLAN \0 " ,
. fill_message_create = netdev_vxlan_fill_message_create ,
. create_type = NETDEV_CREATE_STACKED ,
2014-07-06 16:07:34 +04:00
. config_verify = netdev_vxlan_verify ,
} ;