本文整理汇总了Golang中github.com/coreos/flannel/pkg/ip.FromIP函数的典型用法代码示例。如果您正苦于以下问题:Golang FromIP函数的具体用法?Golang FromIP怎么用?Golang FromIP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FromIP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleL3Miss
func (vb *VXLANBackend) handleL3Miss(miss *netlink.Neigh) {
log.Infof("L3 miss: %v", miss.IP)
rt := vb.rts.findByNetwork(ip.FromIP(miss.IP))
if rt == nil {
log.Infof("Route for %v not found", miss.IP)
return
}
if err := vb.dev.AddL3(neigh{IP: ip.FromIP(miss.IP), MAC: rt.vtepMAC}); err != nil {
log.Errorf("AddL3 failed: %v", err)
} else {
log.Info("AddL3 succeeded")
}
}
示例2: Init
func (rb *HostgwBackend) Init(extIface *net.Interface, extIaddr net.IP, extEaddr net.IP) (*backend.SubnetDef, error) {
rb.extIface = extIface
rb.extIaddr = extIaddr
if !extIaddr.Equal(extEaddr) {
return nil, fmt.Errorf("your PublicIP differs from interface IP, meaning that probably you're on a NAT, which is not supported by host-gw backend")
}
attrs := subnet.LeaseAttrs{
PublicIP: ip.FromIP(extIaddr),
BackendType: "host-gw",
}
l, err := rb.sm.AcquireLease(rb.ctx, rb.network, &attrs)
switch err {
case nil:
rb.lease = l
case context.Canceled, context.DeadlineExceeded:
return nil, err
default:
return nil, fmt.Errorf("failed to acquire lease: %v", err)
}
/* NB: docker will create the local route to `sn` */
return &backend.SubnetDef{
Net: l.Subnet,
MTU: extIface.MTU,
}, nil
}
示例3: RegisterNetwork
func (be *HostgwBackend) RegisterNetwork(ctx context.Context, netname string, config *subnet.Config) (backend.Network, error) {
n := &network{
name: netname,
extIface: be.extIface,
sm: be.sm,
}
attrs := subnet.LeaseAttrs{
PublicIP: ip.FromIP(be.extIface.ExtAddr),
BackendType: "host-gw",
}
l, err := be.sm.AcquireLease(ctx, netname, &attrs)
switch err {
case nil:
n.lease = l
case context.Canceled, context.DeadlineExceeded:
return nil, err
default:
return nil, fmt.Errorf("failed to acquire lease: %v", err)
}
/* NB: docker will create the local route to `sn` */
be.networks[netname] = n
return n, nil
}
示例4: Init
func (rb *HostgwBackend) Init(extIface *net.Interface, extIP net.IP) (*backend.SubnetDef, error) {
rb.extIface = extIface
rb.extIP = extIP
attrs := subnet.LeaseAttrs{
PublicIP: ip.FromIP(extIP),
BackendType: "host-gw",
}
l, err := rb.sm.AcquireLease(rb.ctx, rb.network, &attrs)
switch err {
case nil:
rb.lease = l
case context.Canceled, context.DeadlineExceeded:
return nil, err
default:
return nil, fmt.Errorf("failed to acquire lease: %v", err)
}
/* NB: docker will create the local route to `sn` */
return &backend.SubnetDef{
Net: l.Subnet,
MTU: extIface.MTU,
}, nil
}
示例5: New
func New(sm subnet.Manager, extIface *net.Interface, extIaddr net.IP, extEaddr net.IP) (backend.Backend, error) {
gb := GCEBackend{
sm: sm,
publicIP: ip.FromIP(extEaddr),
mtu: extIface.MTU,
}
return &gb, nil
}
示例6: handleInitialSubnetEvents
func (vb *VXLANBackend) handleInitialSubnetEvents(batch []subnet.Event) error {
log.Infof("Handling initial subnet events")
fdbTable, err := vb.dev.GetL2List()
if err != nil {
return fmt.Errorf("Error fetching L2 table: %v", err)
}
for _, fdbEntry := range fdbTable {
log.Infof("fdb already populated with: %s %s ", fdbEntry.IP, fdbEntry.HardwareAddr)
}
evtMarker := make([]bool, len(batch))
leaseAttrsList := make([]vxlanLeaseAttrs, len(batch))
fdbEntryMarker := make([]bool, len(fdbTable))
for i, evt := range batch {
if evt.Lease.Attrs.BackendType != "vxlan" {
log.Warningf("Ignoring non-vxlan subnet: type=%v", evt.Lease.Attrs.BackendType)
evtMarker[i] = true
continue
}
if err := json.Unmarshal(evt.Lease.Attrs.BackendData, &leaseAttrsList[i]); err != nil {
log.Error("Error decoding subnet lease JSON: ", err)
evtMarker[i] = true
continue
}
for j, fdbEntry := range fdbTable {
if evt.Lease.Attrs.PublicIP.ToIP().Equal(fdbEntry.IP) && bytes.Equal([]byte(leaseAttrsList[i].VtepMAC), []byte(fdbEntry.HardwareAddr)) {
evtMarker[i] = true
fdbEntryMarker[j] = true
break
}
}
vb.rts.set(evt.Lease.Subnet, net.HardwareAddr(leaseAttrsList[i].VtepMAC))
}
for j, marker := range fdbEntryMarker {
if !marker && fdbTable[j].IP != nil {
err := vb.dev.DelL2(neigh{IP: ip.FromIP(fdbTable[j].IP), MAC: fdbTable[j].HardwareAddr})
if err != nil {
log.Error("Delete L2 failed: ", err)
}
}
}
for i, marker := range evtMarker {
if !marker {
err := vb.dev.AddL2(neigh{IP: batch[i].Lease.Attrs.PublicIP, MAC: net.HardwareAddr(leaseAttrsList[i].VtepMAC)})
if err != nil {
log.Error("Add L2 failed: ", err)
}
}
}
return nil
}
示例7: Init
func (m *AllocBackend) Init(extIface *net.Interface, extIP net.IP, ipMasq bool) (*backend.SubnetDef, error) {
attrs := subnet.BaseAttrs{
PublicIP: ip.FromIP(extIP),
}
sn, err := m.sm.AcquireLease(ip.FromIP(extIP), &attrs, m.stop)
if err != nil {
if err == task.ErrCanceled {
return nil, err
} else {
return nil, fmt.Errorf("failed to acquire lease: %v", err)
}
}
return &backend.SubnetDef{
Net: sn,
MTU: extIface.MTU,
}, nil
}
示例8: New
func New(sm subnet.Manager, extIface *net.Interface, extIaddr net.IP, extEaddr net.IP) (backend.Backend, error) {
be := UdpBackend{
sm: sm,
publicIP: ip.FromIP(extEaddr),
// TUN MTU will be smaller b/c of encap (IP+UDP hdrs)
mtu: extIface.MTU - encapOverhead,
}
be.cfg.Port = defaultPort
return &be, nil
}
示例9: Init
func (m *UdpBackend) Init(ctx context.Context, extIface *net.Interface, extIaddr net.IP, extEaddr net.IP) (*backend.SubnetDef, error) {
// Parse our configuration
if len(m.config.Backend) > 0 {
if err := json.Unmarshal(m.config.Backend, &m.cfg); err != nil {
return nil, fmt.Errorf("error decoding UDP backend config: %v", err)
}
}
// Acquire the lease form subnet manager
attrs := subnet.LeaseAttrs{
PublicIP: ip.FromIP(extEaddr),
}
l, err := m.sm.AcquireLease(ctx, m.network, &attrs)
switch err {
case nil:
m.lease = l
case context.Canceled, context.DeadlineExceeded:
return nil, err
default:
return nil, fmt.Errorf("failed to acquire lease: %v", err)
}
// Tunnel's subnet is that of the whole overlay network (e.g. /16)
// and not that of the individual host (e.g. /24)
m.tunNet = ip.IP4Net{
IP: l.Subnet.IP,
PrefixLen: m.config.Network.PrefixLen,
}
// TUN MTU will be smaller b/c of encap (IP+UDP hdrs)
m.mtu = extIface.MTU - encapOverhead
if err = m.initTun(); err != nil {
return nil, err
}
m.conn, err = net.ListenUDP("udp4", &net.UDPAddr{Port: m.cfg.Port})
if err != nil {
return nil, fmt.Errorf("failed to start listening on UDP socket: %v", err)
}
m.ctl, m.ctl2, err = newCtlSockets()
if err != nil {
return nil, fmt.Errorf("failed to create control socket: %v", err)
}
return &backend.SubnetDef{
Lease: l,
MTU: m.mtu,
}, nil
}
示例10: parseSubnetKey
func parseSubnetKey(s string) *ip.IP4Net {
if parts := subnetRegex.FindStringSubmatch(s); len(parts) == 3 {
snIp := net.ParseIP(parts[1]).To4()
prefixLen, err := strconv.ParseUint(parts[2], 10, 5)
if snIp != nil && err == nil {
return &ip.IP4Net{IP: ip.FromIP(snIp), PrefixLen: uint(prefixLen)}
}
}
return nil
}
示例11: parseSubnetKey
func parseSubnetKey(s string) (ip.IP4Net, error) {
if parts := subnetRegex.FindStringSubmatch(s); len(parts) == 3 {
snIp := net.ParseIP(parts[1]).To4()
prefixLen, err := strconv.ParseUint(parts[2], 10, 5)
if snIp != nil && err == nil {
return ip.IP4Net{IP: ip.FromIP(snIp), PrefixLen: uint(prefixLen)}, nil
}
}
return ip.IP4Net{}, errors.New("Error parsing IP Subnet")
}
示例12: newSubnetAttrs
func newSubnetAttrs(extEaddr net.IP, mac net.HardwareAddr) (*subnet.LeaseAttrs, error) {
data, err := json.Marshal(&vxlanLeaseAttrs{hardwareAddr(mac)})
if err != nil {
return nil, err
}
return &subnet.LeaseAttrs{
PublicIP: ip.FromIP(extEaddr),
BackendType: "vxlan",
BackendData: json.RawMessage(data),
}, nil
}
示例13: Init
func (m *UdpBackend) Init(extIface *net.Interface, extIP net.IP, ipMasq bool) (*backend.SubnetDef, error) {
// Parse our configuration
if len(m.rawCfg) > 0 {
if err := json.Unmarshal(m.rawCfg, &m.cfg); err != nil {
return nil, fmt.Errorf("error decoding UDP backend config: %v", err)
}
}
// Acquire the lease form subnet manager
attrs := subnet.BaseAttrs{
PublicIP: ip.FromIP(extIP),
}
sn, err := m.sm.AcquireLease(attrs.PublicIP, &attrs, m.stop)
if err != nil {
if err == task.ErrCanceled {
return nil, err
} else {
return nil, fmt.Errorf("failed to acquire lease: %v", err)
}
}
// Tunnel's subnet is that of the whole overlay network (e.g. /16)
// and not that of the individual host (e.g. /24)
m.tunNet = ip.IP4Net{
IP: sn.IP,
PrefixLen: m.sm.GetConfig().Network.PrefixLen,
}
// TUN MTU will be smaller b/c of encap (IP+UDP hdrs)
m.mtu = extIface.MTU - encapOverhead
if err = m.initTun(ipMasq); err != nil {
return nil, err
}
m.conn, err = net.ListenUDP("udp4", &net.UDPAddr{Port: m.cfg.Port})
if err != nil {
return nil, fmt.Errorf("failed to start listening on UDP socket: %v", err)
}
m.ctl, m.ctl2, err = newCtlSockets()
if err != nil {
return nil, fmt.Errorf("failed to create control socket: %v", err)
}
return &backend.SubnetDef{
Net: sn,
MTU: m.mtu,
}, nil
}
示例14: New
func New(sm subnet.Manager, extIface *net.Interface, extIaddr net.IP, extEaddr net.IP) (backend.Backend, error) {
if !extIaddr.Equal(extEaddr) {
return nil, fmt.Errorf("your PublicIP differs from interface IP, meaning that probably you're on a NAT, which is not supported by host-gw backend")
}
b := &HostgwBackend{
sm: sm,
publicIP: ip.FromIP(extEaddr),
mtu: extIface.MTU,
extIface: extIface,
extIaddr: extIaddr,
}
return b, nil
}
示例15: RegisterNetwork
func (g *GCEBackend) RegisterNetwork(ctx context.Context, network string, config *subnet.Config) (backend.Network, error) {
attrs := subnet.LeaseAttrs{
PublicIP: ip.FromIP(g.extIface.ExtAddr),
}
l, err := g.sm.AcquireLease(ctx, network, &attrs)
switch err {
case nil:
case context.Canceled, context.DeadlineExceeded:
return nil, err
default:
return nil, fmt.Errorf("failed to acquire lease: %v", err)
}
if err = g.ensureAPI(); err != nil {
return nil, err
}
found, err := g.handleMatchingRoute(l.Subnet.String())
if err != nil {
return nil, fmt.Errorf("error handling matching route: %v", err)
}
if !found {
operation, err := g.api.insertRoute(l.Subnet.String())
if err != nil {
return nil, fmt.Errorf("error inserting route: %v", err)
}
err = g.api.pollOperationStatus(operation.Name)
if err != nil {
return nil, fmt.Errorf("insert operaiton failed: ", err)
}
}
return &backend.SimpleNetwork{
SubnetLease: l,
ExtIface: g.extIface,
}, nil
}