@@ -405,19 +405,20 @@ static int hyper_setup_route(struct rtnl_handle *rth,
405405 return 0 ;
406406}
407407
408- static int hyper_set_interface_name (struct rtnl_handle * rth ,
408+ static int hyper_set_interface_attr (struct rtnl_handle * rth ,
409409 int ifindex ,
410- char * new_device_name )
410+ void * data ,
411+ int len ,
412+ int type )
411413{
412414 struct {
413- struct nlmsghdr n ;
414- struct ifinfomsg i ;
415- char buf [1024 ];
416- } req ;
415+ struct nlmsghdr n ;
416+ struct ifinfomsg i ;
417+ char buf [1024 ];
418+ } req ;
417419
418- if (ifindex < 0 || ! new_device_name ) {
420+ if (! rth || ifindex < 0 )
419421 return -1 ;
420- }
421422
422423 memset (& req , 0 , sizeof (req ));
423424 req .n .nlmsg_len = NLMSG_LENGTH (sizeof (struct ifinfomsg ));
@@ -428,21 +429,46 @@ static int hyper_set_interface_name(struct rtnl_handle *rth,
428429 req .i .ifi_change = 0xFFFFFFFF ;
429430 req .i .ifi_index = ifindex ;
430431
431- if (addattr_l (& req .n , sizeof (req ), IFLA_IFNAME ,
432- new_device_name ,
433- strlen ( new_device_name ) + 1 )) {
432+ if (addattr_l (& req .n , sizeof (req ), type ,
433+ data ,
434+ len )) {
434435 fprintf (stderr , "setup attr failed\n" );
435436 return -1 ;
436437 }
437438
438- if (rtnl_talk (rth , & req .n , 0 , 0 , NULL ) < 0 ) {
439+ if (rtnl_talk (rth , & req .n , 0 , 0 , NULL ) < 0 ){
439440 perror ("rtnl_talk failed" );
440441 return -1 ;
441442 }
442443
443444 return 0 ;
444445}
445446
447+ static int hyper_set_interface_name (struct rtnl_handle * rth ,
448+ int ifindex ,
449+ char * new_device_name )
450+ {
451+ if ( !rth || ifindex < 0 || !new_device_name ) {
452+ return -1 ;
453+ }
454+ return hyper_set_interface_attr (rth , ifindex ,
455+ new_device_name ,
456+ strlen (new_device_name )+ 1 ,
457+ IFLA_IFNAME );
458+ }
459+
460+ static int hyper_set_interface_mtu (struct rtnl_handle * rth ,
461+ int ifindex ,
462+ unsigned int mtu )
463+ {
464+ if (!rth || ifindex < 0 ) {
465+ return -1 ;
466+ }
467+ return hyper_set_interface_attr (rth , ifindex , & mtu ,
468+ sizeof (mtu ),
469+ IFLA_MTU );
470+ }
471+
446472static int hyper_setup_interface (struct rtnl_handle * rth ,
447473 struct hyper_interface * iface )
448474{
@@ -505,6 +531,15 @@ static int hyper_setup_interface(struct rtnl_handle *rth,
505531 hyper_set_interface_name (rth , ifindex , iface -> new_device_name );
506532 }
507533
534+ if (iface -> mtu > 0 ) {
535+ fprintf (stdout , "Setting interface MTU to %d\n" , iface -> mtu );
536+ if (hyper_set_interface_mtu (rth , ifindex , iface -> mtu ) < 0 ) {
537+ fprintf (stderr , "set mtu failed for interface %s\n" ,
538+ iface -> device );
539+ return -1 ;
540+ }
541+ }
542+
508543 if (hyper_up_nic (rth , ifindex ) < 0 ) {
509544 fprintf (stderr , "up device %d failed\n" , ifindex );
510545 return -1 ;
0 commit comments