// Join method is invoked when a Sandbox is attached to an endpoint. func (d *driver) Join(nid, eid types.UUID, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error { join := &joinRequest{ NetworkID: string(nid), EndpointID: string(eid), SandboxKey: sboxKey, Options: options, } var ( res joinResponse err error ) if err = d.call("Join", join, &res); err != nil { return err } // Expect each interface ID given by CreateEndpoint to have an // entry at that index in the names supplied here. In other words, // if you supply 0..n interfaces with IDs 0..n above, you should // supply the names in the same order. ifaceNames := res.InterfaceNames for _, iface := range jinfo.InterfaceNames() { i := iface.ID() if i >= len(ifaceNames) || i < 0 { return fmt.Errorf("no correlating interface %d in supplied interface names", i) } supplied := ifaceNames[i] if err := iface.SetNames(supplied.SrcName, supplied.DstName); err != nil { return errorWithRollback(fmt.Sprintf("failed to set interface name: %s", err), d.Leave(nid, eid)) } } var addr net.IP if res.Gateway != "" { if addr = net.ParseIP(res.Gateway); addr == nil { return fmt.Errorf(`unable to parse Gateway "%s"`, res.Gateway) } if jinfo.SetGateway(addr) != nil { return errorWithRollback(fmt.Sprintf("failed to set gateway: %v", addr), d.Leave(nid, eid)) } } if res.GatewayIPv6 != "" { if addr = net.ParseIP(res.GatewayIPv6); addr == nil { return fmt.Errorf(`unable to parse GatewayIPv6 "%s"`, res.GatewayIPv6) } if jinfo.SetGatewayIPv6(addr) != nil { return errorWithRollback(fmt.Sprintf("failed to set gateway IPv6: %v", addr), d.Leave(nid, eid)) } } if jinfo.SetHostsPath(res.HostsPath) != nil { return errorWithRollback(fmt.Sprintf("failed to set hosts path: %s", res.HostsPath), d.Leave(nid, eid)) } if jinfo.SetResolvConfPath(res.ResolvConfPath) != nil { return errorWithRollback(fmt.Sprintf("failed to set resolv.conf path: %s", res.ResolvConfPath), d.Leave(nid, eid)) } return nil }
// Join method is invoked when a Sandbox is attached to an endpoint. func (d *driver) Join(nid, eid types.UUID, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error { defer sandbox.InitOSContext()() network, err := d.getNetwork(nid) if err != nil { return err } endpoint, err := network.getEndpoint(eid) if err != nil { return err } if endpoint == nil { return EndpointNotFoundError(eid) } for _, iNames := range jinfo.InterfaceNames() { // Make sure to set names on the correct interface ID. if iNames.ID() == ifaceID { err = iNames.SetNames(endpoint.srcName, containerVethPrefix) if err != nil { return err } } } err = jinfo.SetGateway(network.bridge.gatewayIPv4) if err != nil { return err } err = jinfo.SetGatewayIPv6(network.bridge.gatewayIPv6) if err != nil { return err } if !network.config.EnableICC { return d.link(network, endpoint, options, true) } return nil }
// Join method is invoked when a Sandbox is attached to an endpoint. func (d *driver) Join(nid, eid types.UUID, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error { if err := validateID(nid, eid); err != nil { return err } n := d.network(nid) if n == nil { return fmt.Errorf("could not find network with id %s", nid) } ep := n.endpoint(eid) if ep == nil { return fmt.Errorf("could not find endpoint with id %s", eid) } if err := n.joinSandbox(); err != nil { return fmt.Errorf("network sandbox join failed: %v", err) } sbox := n.sandbox() name1, name2, err := createVethPair() if err != nil { return err } if err := sbox.AddInterface(name1, "veth", sbox.InterfaceOptions().Master("bridge1")); err != nil { return fmt.Errorf("could not add veth pair inside the network sandbox: %v", err) } veth, err := netlink.LinkByName(name2) if err != nil { return fmt.Errorf("could not find link by name %s: %v", name2, err) } if err := netlink.LinkSetHardwareAddr(veth, ep.mac); err != nil { return fmt.Errorf("could not set mac address to the container interface: %v", err) } for _, iNames := range jinfo.InterfaceNames() { // Make sure to set names on the correct interface ID. if iNames.ID() == 1 { err = iNames.SetNames(name2, "eth") if err != nil { return err } } } err = jinfo.SetGateway(bridgeIP.IP) if err != nil { return err } d.peerDbAdd(nid, eid, ep.addr.IP, ep.mac, d.serfInstance.LocalMember().Addr, true) d.notifyCh <- ovNotify{ action: "join", nid: nid, eid: eid, } return nil }
// Join method is invoked when a Sandbox is attached to an endpoint. func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error { join := &api.JoinRequest{ NetworkID: nid, EndpointID: eid, SandboxKey: sboxKey, Options: options, } var ( res api.JoinResponse err error ) if err = d.call("Join", join, &res); err != nil { return err } // Expect each interface ID given by CreateEndpoint to have an // entry at that index in the names supplied here. In other words, // if you supply 0..n interfaces with IDs 0..n above, you should // supply the names in the same order. ifaceNames := res.InterfaceNames for _, iface := range jinfo.InterfaceNames() { i := iface.ID() if i >= len(ifaceNames) || i < 0 { return fmt.Errorf("no correlating interface %d in supplied interface names", i) } supplied := ifaceNames[i] if err := iface.SetNames(supplied.SrcName, supplied.DstPrefix); err != nil { return errorWithRollback(fmt.Sprintf("failed to set interface name: %s", err), d.Leave(nid, eid)) } } var addr net.IP if res.Gateway != "" { if addr = net.ParseIP(res.Gateway); addr == nil { return fmt.Errorf(`unable to parse Gateway "%s"`, res.Gateway) } if jinfo.SetGateway(addr) != nil { return errorWithRollback(fmt.Sprintf("failed to set gateway: %v", addr), d.Leave(nid, eid)) } } if res.GatewayIPv6 != "" { if addr = net.ParseIP(res.GatewayIPv6); addr == nil { return fmt.Errorf(`unable to parse GatewayIPv6 "%s"`, res.GatewayIPv6) } if jinfo.SetGatewayIPv6(addr) != nil { return errorWithRollback(fmt.Sprintf("failed to set gateway IPv6: %v", addr), d.Leave(nid, eid)) } } if len(res.StaticRoutes) > 0 { routes, err := parseStaticRoutes(res) if err != nil { return err } for _, route := range routes { if jinfo.AddStaticRoute(route.Destination, route.RouteType, route.NextHop, route.InterfaceID) != nil { return errorWithRollback(fmt.Sprintf("failed to set static route: %v", route), d.Leave(nid, eid)) } } } return nil }