@@ -71,7 +71,7 @@ func (csh cniServerHandler) configureDpdkNic(podName, podNamespace, provider, ne
7171 return ovs .SetInterfaceBandwidth (podName , podNamespace , ifaceID , egress , ingress )
7272}
7373
74- func (csh cniServerHandler ) configureNic (podName , podNamespace , provider , netns , containerID , vfDriver , ifName , mac string , mtu int , ip , gateway string , isDefaultRoute , vmMigration bool , routes []request.Route , _ , _ []string , ingress , egress , deviceID , nicType , latency , limit , loss , jitter string , gwCheckMode int , u2oInterconnectionIP , oldPodName string ) ([]request.Route , error ) {
74+ func (csh cniServerHandler ) configureNic (podName , podNamespace , provider , netns , containerID , vfDriver , ifName , mac string , mtu int , ip , gateway string , isDefaultRoute , vmMigration bool , routes []request.Route , _ , _ []string , ingress , egress , deviceID , latency , limit , loss , jitter string , gwCheckMode int , u2oInterconnectionIP , oldPodName string ) ([]request.Route , error ) {
7575 var err error
7676 var hostNicName , containerNicName , pfPci string
7777 var vfID int
@@ -131,7 +131,7 @@ func (csh cniServerHandler) configureNic(podName, podNamespace, provider, netns,
131131 }
132132 defer func () {
133133 if err != nil {
134- if err := csh .rollbackOvsPort (hostNicName , containerNicName , nicType ); err != nil {
134+ if err := csh .rollbackOvsPort (hostNicName ); err != nil {
135135 klog .Errorf ("failed to rollback ovs port %s, %v" , hostNicName , err )
136136 return
137137 }
@@ -227,7 +227,7 @@ func (csh cniServerHandler) configureNic(podName, podNamespace, provider, netns,
227227 klog .Error (err )
228228 return nil , err
229229 }
230- finalRoutes , err := csh .configureContainerNic (podName , podNamespace , containerNicName , ifName , ip , gateway , isDefaultRoute , vmMigration , routes , macAddr , podNS , mtu , nicType , gwCheckMode , u2oInterconnectionIP )
230+ finalRoutes , err := csh .configureContainerNic (podName , podNamespace , containerNicName , ifName , ip , gateway , isDefaultRoute , vmMigration , routes , macAddr , podNS , mtu , gwCheckMode , u2oInterconnectionIP )
231231 if err != nil {
232232 klog .Error (err )
233233 return nil , err
@@ -309,13 +309,8 @@ func (csh cniServerHandler) deleteNic(podName, podNamespace, containerID, netns,
309309
310310 nicName = yusur .GetYusurNicVfRepresentor (pfIndex , vfIndex )
311311 } else {
312- hostNicName , containerNicName := generateNicName (containerID , ifName )
313-
314- if nicType == util .InternalType {
315- nicName = containerNicName
316- } else {
317- nicName = hostNicName
318- }
312+ hostNicName , _ := generateNicName (containerID , ifName )
313+ nicName = hostNicName
319314 }
320315 // Remove ovs port
321316 output , err := ovs .Exec (ovs .IfExists , "--with-iface" , "del-port" , "br-int" , nicName )
@@ -365,18 +360,12 @@ func (csh cniServerHandler) deleteNic(podName, podNamespace, containerID, netns,
365360 return nil
366361}
367362
368- func (csh cniServerHandler ) rollbackOvsPort (hostNicName , containerNicName , nicType string ) (err error ) {
369- var nicName string
370- if nicType == util .InternalType {
371- nicName = containerNicName
372- } else {
373- nicName = hostNicName
374- }
375- output , err := ovs .Exec (ovs .IfExists , "--with-iface" , "del-port" , "br-int" , nicName )
363+ func (csh cniServerHandler ) rollbackOvsPort (hostNicName string ) (err error ) {
364+ output , err := ovs .Exec (ovs .IfExists , "--with-iface" , "del-port" , "br-int" , hostNicName )
376365 if err != nil {
377366 klog .Warningf ("failed to delete down ovs port %v, %q" , err , output )
378367 }
379- klog .Infof ("rollback ovs port success %s" , nicName )
368+ klog .Infof ("rollback ovs port success %s" , hostNicName )
380369 return err
381370}
382371
@@ -410,7 +399,7 @@ func configureHostNic(nicName string) error {
410399 return nil
411400}
412401
413- func (csh cniServerHandler ) configureContainerNic (podName , podNamespace , nicName , ifName , ipAddr , gateway string , isDefaultRoute , vmMigration bool , routes []request.Route , macAddr net.HardwareAddr , netns ns.NetNS , mtu int , nicType string , gwCheckMode int , u2oInterconnectionIP string ) ([]request.Route , error ) {
402+ func (csh cniServerHandler ) configureContainerNic (podName , podNamespace , nicName , ifName , ipAddr , gateway string , isDefaultRoute , vmMigration bool , routes []request.Route , macAddr net.HardwareAddr , netns ns.NetNS , mtu , gwCheckMode int , u2oInterconnectionIP string ) ([]request.Route , error ) {
414403 containerLink , err := netlink .LinkByName (nicName )
415404 if err != nil {
416405 return nil , fmt .Errorf ("can not find container nic %s: %w" , nicName , err )
@@ -432,33 +421,14 @@ func (csh cniServerHandler) configureContainerNic(podName, podNamespace, nicName
432421 detectIPv4Conflict := ! vmMigration && csh .Config .EnableArpDetectIPConflict
433422 var finalRoutes []request.Route
434423 err = ns .WithNetNSPath (netns .Path (), func (_ ns.NetNS ) error {
435- interfaceName := nicName
436- if nicType != util .InternalType {
437- interfaceName = ifName
438- if err = netlink .LinkSetName (containerLink , ifName ); err != nil {
439- klog .Error (err )
440- return err
441- }
424+ if err = netlink .LinkSetName (containerLink , ifName ); err != nil {
425+ klog .Error (err )
426+ return err
442427 }
443428
444- if nicType == util .InternalType {
445- if err = addAdditionalNic (ifName ); err != nil {
446- klog .Error (err )
447- return err
448- }
449- if err = configureAdditionalNic (ifName , ipAddr ); err != nil {
450- klog .Error (err )
451- return err
452- }
453- if err = configureNic (nicName , ipAddr , macAddr , mtu , detectIPv4Conflict , ipv6DAD , false , false ); err != nil {
454- klog .Error (err )
455- return err
456- }
457- } else {
458- if err = configureNic (ifName , ipAddr , macAddr , mtu , detectIPv4Conflict , ipv6DAD , true , false ); err != nil {
459- klog .Error (err )
460- return err
461- }
429+ if err = configureNic (ifName , ipAddr , macAddr , mtu , detectIPv4Conflict , ipv6DAD , true , false ); err != nil {
430+ klog .Error (err )
431+ return err
462432 }
463433
464434 if isDefaultRoute {
@@ -537,38 +507,38 @@ func (csh cniServerHandler) configureContainerNic(podName, podNamespace, nicName
537507
538508 if gwCheckMode != gatewayCheckModeDisabled {
539509 if util .CheckProtocol (ipAddr ) == kubeovnv1 .ProtocolIPv6 || util .CheckProtocol (ipAddr ) == kubeovnv1 .ProtocolDual {
540- addrsFlags , err := waitIPv6AddressPreferred (interfaceName , 10 , 500 * time .Millisecond , ipv6DAD )
510+ addrsFlags , err := waitIPv6AddressPreferred (ifName , 10 , 500 * time .Millisecond , ipv6DAD )
541511 if err != nil {
542512 klog .Error (err )
543513 return err
544514 }
545515 for addr , flags := range addrsFlags {
546516 if flags & unix .IFA_F_DADFAILED == 0 {
547- klog .Errorf ("address %s on interface %s is not ready, flags: 0x%x" , addr , interfaceName , flags )
517+ klog .Errorf ("address %s on interface %s is not ready, flags: 0x%x" , addr , ifName , flags )
548518 continue
549519 }
550- klog .Errorf ("IPv6 DAD of address %s on interface %s failed, flags: 0x%x" , addr , interfaceName , flags )
551- available , mac , err := util .DuplicateAddressDetection (interfaceName , addr )
520+ klog .Errorf ("IPv6 DAD of address %s on interface %s failed, flags: 0x%x" , addr , ifName , flags )
521+ available , mac , err := util .DuplicateAddressDetection (ifName , addr )
552522 if err != nil {
553- klog .Errorf ("failed to perform IPv6 DAD for address %s on interface %s: %v" , addr , interfaceName , err )
523+ klog .Errorf ("failed to perform IPv6 DAD for address %s on interface %s: %v" , addr , ifName , err )
554524 return err
555525 }
556526 if ! available && mac != nil {
557527 return fmt .Errorf ("IP address %s has already been used by host with MAC %s" , addr , mac )
558528 }
559529 }
560530 if len (addrsFlags ) != 0 {
561- return fmt .Errorf ("ip address(es) %s on interface %s are not in preferred state" , strings .Join (slices .Collect (maps .Keys (addrsFlags )), "," ), interfaceName )
531+ return fmt .Errorf ("ip address(es) %s on interface %s are not in preferred state" , strings .Join (slices .Collect (maps .Keys (addrsFlags )), "," ), ifName )
562532 }
563533 }
564534
565535 if u2oInterconnectionIP != "" {
566- if err = csh .checkGatewayReady (podName , podNamespace , gwCheckMode , interfaceName , ipAddr , u2oInterconnectionIP , true ); err != nil {
536+ if err = csh .checkGatewayReady (podName , podNamespace , gwCheckMode , ifName , ipAddr , u2oInterconnectionIP , true ); err != nil {
567537 klog .Error (err )
568538 return err
569539 }
570540 }
571- if err = csh .checkGatewayReady (podName , podNamespace , gwCheckMode , interfaceName , ipAddr , gateway , true ); err != nil {
541+ if err = csh .checkGatewayReady (podName , podNamespace , gwCheckMode , ifName , ipAddr , gateway , true ); err != nil {
572542 klog .Error (err )
573543 return err
574544 }
@@ -1608,13 +1578,7 @@ func (c *Controller) removeProviderNic(nicName, brName string) error {
16081578 return err
16091579 }
16101580
1611- scopeOrders := [... ]netlink.Scope {
1612- netlink .SCOPE_HOST ,
1613- netlink .SCOPE_LINK ,
1614- netlink .SCOPE_SITE ,
1615- netlink .SCOPE_UNIVERSE ,
1616- }
1617- for _ , scope := range scopeOrders {
1581+ for _ , scope := range routeScopeOrders {
16181582 for _ , route := range routes {
16191583 if route .Gw == nil && route .Dst != nil && route .Dst .IP .IsLinkLocalUnicast () {
16201584 // skip 169.254.0.0/16 and fe80::/10
@@ -1796,57 +1760,6 @@ func renameLink(curName, newName string) error {
17961760 return netlink .LinkSetUp (link )
17971761}
17981762
1799- func (csh cniServerHandler ) configureNicWithInternalPort (podName , podNamespace , provider , netns , containerID , ifName , mac string , mtu int , ip , gateway string , isDefaultRoute , detectIPConflict bool , routes []request.Route , _ , _ []string , ingress , egress , _ , nicType , latency , limit , loss , jitter string , gwCheckMode int , u2oInterconnectionIP string ) (string , []request.Route , error ) {
1800- _ , containerNicName := generateNicName (containerID , ifName )
1801- ipStr := util .GetIPWithoutMask (ip )
1802- ifaceID := ovs .PodNameToPortName (podName , podNamespace , provider )
1803- ovs .CleanDuplicatePort (ifaceID , containerNicName )
1804-
1805- // Add container iface to ovs port as internal port
1806- output , err := ovs .Exec (ovs .MayExist , "add-port" , "br-int" , containerNicName , "--" ,
1807- "set" , "interface" , containerNicName , "type=internal" , "--" ,
1808- "set" , "interface" , containerNicName , "external_ids:iface-id=" + ifaceID ,
1809- "external_ids:vendor=" + util .CniTypeName ,
1810- "external_ids:pod_name=" + podName ,
1811- "external_ids:pod_namespace=" + podNamespace ,
1812- "external_ids:ip=" + ipStr ,
1813- "external_ids:pod_netns=" + netns )
1814- if err != nil {
1815- err := fmt .Errorf ("add nic to ovs failed %w: %q" , err , output )
1816- klog .Error (err )
1817- return containerNicName , nil , err
1818- }
1819- defer func () {
1820- if err != nil {
1821- if err := csh .rollbackOvsPort ("" , containerNicName , nicType ); err != nil {
1822- klog .Errorf ("failed to rollback ovs port %s, %v" , containerNicName , err )
1823- return
1824- }
1825- }
1826- }()
1827-
1828- // container nic must use same mac address from pod annotation, otherwise ovn will reject these packets by default
1829- macAddr , err := net .ParseMAC (mac )
1830- if err != nil {
1831- return containerNicName , nil , fmt .Errorf ("failed to parse mac %s %w" , macAddr , err )
1832- }
1833-
1834- if err = ovs .SetInterfaceBandwidth (podName , podNamespace , ifaceID , egress , ingress ); err != nil {
1835- return containerNicName , nil , err
1836- }
1837-
1838- if err = ovs .SetNetemQos (podName , podNamespace , ifaceID , latency , limit , loss , jitter ); err != nil {
1839- return containerNicName , nil , err
1840- }
1841-
1842- podNS , err := ns .GetNS (netns )
1843- if err != nil {
1844- return containerNicName , nil , fmt .Errorf ("failed to open netns %q: %w" , netns , err )
1845- }
1846- routes , err = csh .configureContainerNic (podName , podNamespace , containerNicName , ifName , ip , gateway , isDefaultRoute , detectIPConflict , routes , macAddr , podNS , mtu , nicType , gwCheckMode , u2oInterconnectionIP )
1847- return containerNicName , routes , err
1848- }
1849-
18501763func (csh cniServerHandler ) removeDefaultRoute (netns string , ipv4 , ipv6 bool ) error {
18511764 podNS , err := ns .GetNS (netns )
18521765 if err != nil {
@@ -1883,72 +1796,6 @@ func (csh cniServerHandler) removeDefaultRoute(netns string, ipv4, ipv6 bool) er
18831796 })
18841797}
18851798
1886- // https://github.com/antrea-io/antrea/issues/1691
1887- func configureAdditionalNic (link , ip string ) error {
1888- nodeLink , err := netlink .LinkByName (link )
1889- if err != nil {
1890- return fmt .Errorf ("can not find nic %s %w" , link , err )
1891- }
1892-
1893- ipDelMap := make (map [string ]netlink.Addr )
1894- ipAddMap := make (map [string ]netlink.Addr )
1895- ipAddrs , err := netlink .AddrList (nodeLink , 0x0 )
1896- if err != nil {
1897- return fmt .Errorf ("can not get addr %s %w" , nodeLink , err )
1898- }
1899- for _ , ipAddr := range ipAddrs {
1900- if ipAddr .IP .IsLinkLocalUnicast () {
1901- // skip 169.254.0.0/16 and fe80::/10
1902- continue
1903- }
1904- ipDelMap [ipAddr .IPNet .String ()] = ipAddr
1905- }
1906-
1907- for ipStr := range strings .SplitSeq (ip , "," ) {
1908- // Do not reassign same address for link
1909- if _ , ok := ipDelMap [ipStr ]; ok {
1910- delete (ipDelMap , ipStr )
1911- continue
1912- }
1913-
1914- ipAddr , err := netlink .ParseAddr (ipStr )
1915- if err != nil {
1916- return fmt .Errorf ("can not parse %s %w" , ipStr , err )
1917- }
1918- ipAddMap [ipStr ] = * ipAddr
1919- }
1920-
1921- for _ , addr := range ipDelMap {
1922- if err = netlink .AddrDel (nodeLink , & addr ); err != nil {
1923- return fmt .Errorf ("delete address %s %w" , addr , err )
1924- }
1925- }
1926- for _ , addr := range ipAddMap {
1927- if err = netlink .AddrAdd (nodeLink , & addr ); err != nil {
1928- return fmt .Errorf ("can not add address %v to nic %s, %w" , addr , link , err )
1929- }
1930- }
1931-
1932- return nil
1933- }
1934-
1935- func addAdditionalNic (ifName string ) error {
1936- dummy := & netlink.Dummy {
1937- LinkAttrs : netlink.LinkAttrs {
1938- Name : ifName ,
1939- },
1940- }
1941-
1942- if err := netlink .LinkAdd (dummy ); err != nil {
1943- if err := netlink .LinkDel (dummy ); err != nil {
1944- klog .Errorf ("failed to delete static iface %v, err %v" , ifName , err )
1945- return err
1946- }
1947- return fmt .Errorf ("failed to create static iface %v, err %w" , ifName , err )
1948- }
1949- return nil
1950- }
1951-
19521799func setVfMac (deviceID string , vfIndex int , mac string ) error {
19531800 macAddr , err := net .ParseMAC (mac )
19541801 if err != nil {
0 commit comments