@@ -614,8 +614,9 @@ static int hyper_setup_interface(struct rtnl_handle *rth,
614614 char buf [256 ];
615615 } req ;
616616 int ifindex ;
617+ struct hyper_ipaddress * ip ;
617618
618- if (!( iface -> device && iface -> ipaddr && iface -> mask )) {
619+ if (!iface -> device || list_empty ( & iface -> ipaddresses )) {
619620 fprintf (stderr , "interface information incorrect\n" );
620621 return -1 ;
621622 }
@@ -635,26 +636,28 @@ static int hyper_setup_interface(struct rtnl_handle *rth,
635636 req .ifa .ifa_index = ifindex ;
636637 req .ifa .ifa_scope = 0 ;
637638
638- if (get_addr_ipv4 ((uint8_t * )& data , iface -> ipaddr ) <= 0 ) {
639- fprintf (stderr , "get addr failed\n" );
640- return -1 ;
641- }
639+ list_for_each_entry (ip , & iface -> ipaddresses , list ) {
640+ if (get_addr_ipv4 ((uint8_t * )& data , ip -> addr ) <= 0 ) {
641+ fprintf (stderr , "get addr failed\n" );
642+ return -1 ;
643+ }
642644
643- if (addattr_l (& req .n , sizeof (req ), IFA_LOCAL , & data , 4 )) {
644- fprintf (stderr , "setup attr failed\n" );
645- return -1 ;
646- }
645+ if (addattr_l (& req .n , sizeof (req ), IFA_LOCAL , & data , 4 )) {
646+ fprintf (stderr , "setup attr failed\n" );
647+ return -1 ;
648+ }
647649
648- if (get_netmask (& mask , iface -> mask ) < 0 ) {
649- fprintf (stderr , "get netamsk failed\n" );
650- return -1 ;
651- }
650+ if (get_netmask (& mask , ip -> mask ) < 0 ) {
651+ fprintf (stderr , "get netamsk failed\n" );
652+ return -1 ;
653+ }
652654
653- req .ifa .ifa_prefixlen = mask ;
654- fprintf (stdout , "interface get netamsk %d %s\n" , req .ifa .ifa_prefixlen , iface -> mask );
655- if (rtnl_talk (rth , & req .n , 0 , 0 , NULL ) < 0 ) {
656- perror ("rtnl_talk failed" );
657- return -1 ;
655+ req .ifa .ifa_prefixlen = mask ;
656+ fprintf (stdout , "interface get netamsk %d %s\n" , req .ifa .ifa_prefixlen , ip -> mask );
657+ if (rtnl_talk (rth , & req .n , 0 , 0 , NULL ) < 0 ) {
658+ perror ("rtnl_talk failed" );
659+ return -1 ;
660+ }
658661 }
659662
660663 if (iface -> new_device_name && strcmp (iface -> new_device_name , iface -> device )) {
@@ -681,8 +684,9 @@ static int hyper_cleanup_interface(struct rtnl_handle *rth,
681684 char buf [256 ];
682685 } req ;
683686 int ifindex ;
687+ struct hyper_ipaddress * ip ;
684688
685- if (!( iface -> device && iface -> ipaddr && iface -> mask )) {
689+ if (!iface -> device || list_empty ( & iface -> ipaddresses )) {
686690 fprintf (stderr , "interface information incorrect\n" );
687691 return -1 ;
688692 }
@@ -702,26 +706,28 @@ static int hyper_cleanup_interface(struct rtnl_handle *rth,
702706 req .ifa .ifa_index = ifindex ;
703707 req .ifa .ifa_scope = 0 ;
704708
705- if (get_addr_ipv4 ((uint8_t * )& data , iface -> ipaddr ) <= 0 ) {
706- fprintf (stderr , "get addr failed\n" );
707- return -1 ;
708- }
709+ list_for_each_entry (ip , & iface -> ipaddresses , list ) {
710+ if (get_addr_ipv4 ((uint8_t * )& data , ip -> addr ) <= 0 ) {
711+ fprintf (stderr , "get addr failed\n" );
712+ return -1 ;
713+ }
709714
710- if (addattr_l (& req .n , sizeof (req ), IFA_LOCAL , & data , 4 )) {
711- fprintf (stderr , "setup attr failed\n" );
712- return -1 ;
713- }
715+ if (addattr_l (& req .n , sizeof (req ), IFA_LOCAL , & data , 4 )) {
716+ fprintf (stderr , "setup attr failed\n" );
717+ return -1 ;
718+ }
714719
715- if (get_netmask (& mask , iface -> mask ) < 0 ) {
716- fprintf (stderr , "get netamsk failed\n" );
717- return -1 ;
718- }
720+ if (get_netmask (& mask , ip -> mask ) < 0 ) {
721+ fprintf (stderr , "get netamsk failed\n" );
722+ return -1 ;
723+ }
719724
720- req .ifa .ifa_prefixlen = mask ;
721- fprintf (stdout , "interface get netamsk %d %s\n" , req .ifa .ifa_prefixlen , iface -> mask );
722- if (rtnl_talk (rth , & req .n , 0 , 0 , NULL ) < 0 ) {
723- perror ("rtnl_talk failed" );
724- return -1 ;
725+ req .ifa .ifa_prefixlen = mask ;
726+ fprintf (stdout , "interface get netamsk %d %s\n" , req .ifa .ifa_prefixlen , ip -> mask );
727+ if (rtnl_talk (rth , & req .n , 0 , 0 , NULL ) < 0 ) {
728+ perror ("rtnl_talk failed" );
729+ return -1 ;
730+ }
725731 }
726732
727733 /* Don't down&remove lo device */
@@ -838,9 +844,7 @@ void hyper_cleanup_network(struct hyper_pod *pod)
838844 if (hyper_cleanup_interface (& rth , iface ) < 0 )
839845 fprintf (stderr , "link down device %s failed\n" , iface -> device );
840846
841- free (iface -> device );
842- free (iface -> ipaddr );
843- free (iface -> mask );
847+ hyper_free_interface (iface );
844848 }
845849
846850 free (pod -> iface );
@@ -874,9 +878,7 @@ int hyper_cmd_setup_interface(char *json, int length)
874878 }
875879 ret = 0 ;
876880out1 :
877- free (iface -> device );
878- free (iface -> ipaddr );
879- free (iface -> mask );
881+ hyper_free_interface (iface );
880882 free (iface );
881883out :
882884 netlink_close (& rth );
0 commit comments