// AddToBridge adds network interfaces to network bridge.
// It is equivalent of running: ip link set ${netIfc name} master ${netBridge name}
// It returns error when it fails to add the network interface to bridge.
346828
func AddToBridge(netIfc, netBridge *net.Interface) error {
	return netlink.NetworkSetMaster(netIfc, netBridge)
}
1260056
func (s *Stack) AddAddressWithOptions(id tcpip.NICID, protocol tcpip.NetworkProtocolNumber, addr tcpip.Address, peb PrimaryEndpointBehavior) *tcpip.Error {
	s.mu.RLock()
	defer s.mu.RUnlock()

	nic := s.nics[id]
	if nic == nil {
		return tcpip.ErrUnknownNICID
	}

	return nic.AddAddressWithOptions(protocol, addr, peb)
}
364272
func addMaster(netplugin *plugin.NetPlugin, srvInfo objdb.ServiceInfo) error {
	// save it in db
	MasterDB[masterKey(srvInfo)] = &srvInfo
	// tell the plugin about the master
	return netplugin.AddMaster(core.ServiceInfo{
		HostAddr: srvInfo.HostAddr,
		Port:     netmasterRPCPort,
	})
}
851922
func (ini *Init) Add(initFn func() (interface{}, error)) *Init {
	if ini == nil {
		ini = New()
	}
	return ini.add(false, initFn)
}
169049
func (p *Packet) AddIPLayer(srcIPstr string, dstIPstr string) error {

	if p.ipLayer != nil {
		return errors.New("ip layer already exists")
	}

	var srcIP, dstIP net.IP

	//IP address of the source
	srcIP = net.ParseIP(srcIPstr)

	if srcIP == nil {
		return errors.New("no source ip given")
	}

	//IP address of the destination
	dstIP = net.ParseIP(dstIPstr)

	if dstIP == nil {
		return errors.New("no destination ip given")
	}

	//IP packet header
	p.ipLayer = &layers.IPv4{
		SrcIP:    srcIP,
		DstIP:    dstIP,
		Version:  4,
		TTL:      64,
		Protocol: layers.IPProtocolTCP,
	}

	return nil
}
1107245
func (l *LinkNode) AddAddress(addr net.Addr) error {
	for _, a := range l.Addresses {
		if a.String() == addr.String() {
			return nil
		}
	}

	l.Addresses = append(l.Addresses, addr)

	return l.Sync()
}
807148
func (c *CNIConfig) AddNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) (types.Result, error) {
	result, err := c.addNetwork(ctx, net.Network.Name, net.Network.CNIVersion, net, nil, rt)
	if err != nil {
		return nil, err
	}

	if err = setCachedResult(result, net.Network.Name, rt); err != nil {
		return nil, fmt.Errorf("failed to set network %q cached result: %v", net.Network.Name, err)
	}

	return result, nil
}
606787
func (g *GroupOperations) Add(connectionID string) {
	g.e.addToGroup(g.group, connectionID)
}
1270630
func (t *VLANsTable) add(c context.Context) error {
	// Avoid using the database connection to prepare unnecessary statements.
	if len(t.additions) == 0 {
		return nil
	}

	db := database.Get(c)
	stmt, err := db.PrepareContext(c, `
		INSERT INTO vlans (id, alias, state, cidr_block)
		VALUES (?, ?, ?, ?)
	`)
	if err != nil {
		return errors.Annotate(err, "failed to prepare statement").Err()
	}
	defer stmt.Close()

	// Add each VLAN to the database, and update the slice of VLANs with each addition.
	for len(t.additions) > 0 {
		vlan := t.additions[0]
		_, err := stmt.ExecContext(c, vlan.Id, vlan.Alias, vlan.State, vlan.CidrBlock)
		if err != nil {
			return errors.Annotate(err, "failed to add VLAN %d", vlan.Id).Err()
		}
		t.current = append(t.current, vlan)
		t.additions = t.additions[1:]
		logging.Infof(c, "Added VLAN %d", vlan.Id)
	}
	return nil
}
1278170
func (gw *Gateway) AddBridge(cfg *config.Bridge) error {
	br := gw.Router.getBridge(cfg.Account)
	if br == nil {
		br = bridge.New(cfg)
		br.Config = gw.Router.Config
		br.General = &gw.BridgeValues().General
		br.Log = gw.logger.WithFields(logrus.Fields{"prefix": br.Protocol})
		brconfig := &bridge.Config{
			Remote: gw.Message,
			Bridge: br,
		}
		// add the actual bridger for this protocol to this bridge using the bridgeMap
		if _, ok := gw.Router.BridgeMap[br.Protocol]; !ok {
			gw.logger.Fatalf("Incorrect protocol %s specified in gateway configuration %s, exiting.", br.Protocol, cfg.Account)
		}
		br.Bridger = gw.Router.BridgeMap[br.Protocol](brconfig)
	}
	gw.mapChannelsToBridge(br)
	gw.Bridges[cfg.Account] = br
	return nil
}
636912
func bridgeConfiguration(input string) (string, error) {
	values := parseLXDBridgeConfigValues(input)
	ipAddr := net.ParseIP(values["LXD_IPV4_ADDR"])

	if ipAddr == nil || ipAddr.To4() == nil {
		logger.Infof("LXD_IPV4_ADDR is not set; searching for unused subnet")
		subnet, err := findNextAvailableIPv4Subnet()
		if err != nil {
			return "", errors.Trace(err)
		}
		logger.Infof("setting LXD_IPV4_ADDR=10.0.%s.1", subnet)
		return editLXDBridgeFile(input, subnet), nil
	}
	return input, nil
}
983873
func (g *Graph) Add(n interface{}) *Graph {

	if g == nil {
		return nil
	}

	if node, ok := n.(*Graph); ok && node != nil {
		g.Out = append(g.Out, node)
		return node
	}

	gg := Graph{n, nil}
	g.Out = append(g.Out, &gg)
	return &gg
}
1107740
func (bridge *Bridge) Put(path string, params interface{}) ([]byte, io.Reader, error) {
	uri := fmt.Sprintf("http://" + bridge.IPAddress + path)
	client := &http.Client{Timeout: time.Second * 5}

	data, err := json.Marshal(params)
	if err != nil {
		err = errors.New("unable to marshal PUT request interface")
		return []byte{}, nil, err
	}
	//fmt.Println("\n\nPARAMS: ", params)

	request, _ := http.NewRequest("PUT", uri, bytes.NewReader(data))
	resp, err := client.Do(request)
	if err != nil {
		err = errors.New("unable to access bridge")
		return []byte{}, nil, err
	}
	return HandleResponse(resp)
}
740913
func (np *Netplan) BridgeEthernetById(deviceId string, bridgeName string) (err error) {
	ethernet, ok := np.Network.Ethernets[deviceId]
	if !ok {
		return errors.NotFoundf("ethernet device with id %q for bridge %q", deviceId, bridgeName)
	}
	shouldCreate, err := np.shouldCreateBridge(deviceId, bridgeName)
	if !shouldCreate {
		// err may be nil, but we shouldn't continue creating
		return errors.Trace(err)
	}
	np.createBridgeFromInterface(bridgeName, deviceId, &ethernet.Interface)
	np.Network.Ethernets[deviceId] = ethernet
	return nil
}
504879
func (s *ProxyLBSetting) AddServer(ip string, port int, enabled bool) {
	var record ProxyLBServer
	var isExist = false
	for i := range s.Servers {
		if s.Servers[i].IPAddress == ip && s.Servers[i].Port == port {
			isExist = true
			s.Servers[i].Enabled = enabled
		}
	}

	if !isExist {
		record = ProxyLBServer{
			IPAddress: ip,
			Port:      port,
			Enabled:   enabled,
		}
		s.Servers = append(s.Servers, record)
	}
}
1290755
func (ic *InstanceCount) AddConnected(n int, project, server, zone string) {
	for i, c := range ic.Connected {
		if c.Project == project && c.Server == server && c.Zone == zone {
			ic.Connected[i].Count += n
			return
		}
	}
	ic.Connected = append(ic.Connected, connectedCount{
		Count:   n,
		Project: project,
		Server:  server,
		Zone:    zone,
	})
}
967989
func (p *proxy_PerHost) AddNetwork(net *net.IPNet) {
	p.bypassNetworks = append(p.bypassNetworks, net)
}