2014-06-16 10:24:33 +04:00
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd .
Copyright 2014 Susant Sahani < susant @ redhat . com >
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 <netinet/ether.h>
# include <arpa/inet.h>
# include <net/if.h>
# include "sd-rtnl.h"
2014-07-06 16:07:34 +04:00
# include "networkd-netdev-vxlan.h"
2014-06-21 03:45:45 +04:00
# include "missing.h"
2014-06-16 10:24:33 +04:00
2014-07-06 16:07:34 +04:00
static int netdev_vxlan_fill_message_create ( NetDev * netdev , Link * link , sd_rtnl_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 ) {
r = sd_rtnl_message_append_u32 ( m , IFLA_VXLAN_ID , v - > id ) ;
2014-06-16 10:24:33 +04:00
if ( r < 0 ) {
log_error_netdev ( netdev ,
" Could not append IFLA_VXLAN_ID attribute: %s " ,
strerror ( - r ) ) ;
return r ;
}
}
2014-07-16 15:17:10 +04:00
r = sd_rtnl_message_append_in_addr ( m , IFLA_VXLAN_GROUP , & v - > group . in ) ;
2014-06-16 10:24:33 +04:00
if ( r < 0 ) {
log_error_netdev ( netdev ,
" Could not append IFLA_VXLAN_GROUP attribute: %s " ,
strerror ( - r ) ) ;
return r ;
}
r = sd_rtnl_message_append_u32 ( m , IFLA_VXLAN_LINK , link - > ifindex ) ;
if ( r < 0 ) {
log_error_netdev ( netdev ,
" Could not append IFLA_VXLAN_LINK attribute: %s " ,
strerror ( - r ) ) ;
return r ;
}
2014-07-16 15:17:10 +04:00
if ( v - > ttl ) {
r = sd_rtnl_message_append_u8 ( m , IFLA_VXLAN_TTL , v - > ttl ) ;
2014-06-16 10:24:33 +04:00
if ( r < 0 ) {
log_error_netdev ( netdev ,
" Could not append IFLA_VXLAN_TTL attribute: %s " ,
strerror ( - r ) ) ;
return r ;
}
}
2014-07-16 15:17:10 +04:00
if ( v - > tos ) {
r = sd_rtnl_message_append_u8 ( m , IFLA_VXLAN_TOS , v - > tos ) ;
2014-06-16 10:24:33 +04:00
if ( r < 0 ) {
log_error_netdev ( netdev ,
" Could not append IFLA_VXLAN_TOS attribute: %s " ,
strerror ( - r ) ) ;
return r ;
}
}
2014-07-16 15:17:10 +04:00
r = sd_rtnl_message_append_u8 ( m , IFLA_VXLAN_LEARNING , v - > learning ) ;
2014-06-16 10:24:33 +04:00
if ( r < 0 ) {
log_error_netdev ( netdev ,
" Could not append IFLA_VXLAN_LEARNING attribute: %s " ,
strerror ( - r ) ) ;
return r ;
}
return r ;
}
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 ;
}
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 ,
} ;