Fix routing between containers on same host
This commit is contained in:
		
							
								
								
									
										22
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								main.go
									
									
									
									
									
								
							| @@ -259,8 +259,28 @@ func configureContainerInterface(containerNS netns.NsHandle, ifName string, cont | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if hostLLAddr != nil { | 	if hostLLAddr != nil { | ||||||
| 		// Add route to Mycelium network via host veth | 		// First remove any existing route to our /64 | ||||||
|  | 		myceliumPrefix := &net.IPNet{ | ||||||
|  | 			IP:   containerIP.Mask(net.CIDRMask(64, 128)), | ||||||
|  | 			Mask: net.CIDRMask(64, 128), | ||||||
|  | 		} | ||||||
|  | 		existingRoute := &netlink.Route{ | ||||||
|  | 			Dst: myceliumPrefix, | ||||||
|  | 		} | ||||||
|  | 		netlink.RouteDel(existingRoute) | ||||||
|  |  | ||||||
|  | 		// Add route to our /64 via host veth | ||||||
| 		route := &netlink.Route{ | 		route := &netlink.Route{ | ||||||
|  | 			Dst:       myceliumPrefix, | ||||||
|  | 			Gw:        hostLLAddr, | ||||||
|  | 			LinkIndex: link.Attrs().Index, | ||||||
|  | 		} | ||||||
|  | 		if err := netlink.RouteAdd(route); err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		// Add route to Mycelium network via host veth | ||||||
|  | 		route = &netlink.Route{ | ||||||
| 			Dst: &net.IPNet{ | 			Dst: &net.IPNet{ | ||||||
| 				IP:   net.ParseIP("400::"), | 				IP:   net.ParseIP("400::"), | ||||||
| 				Mask: net.CIDRMask(7, 128), | 				Mask: net.CIDRMask(7, 128), | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user