Skip to content

Question: Adding a network interface #21

@henrikkorsgaard

Description

@henrikkorsgaard

Forgive me if this is asking about a trivial thing.

I am trying to add the capability of adding a network interface to a physical device similar to the iw command sudo iw phy phy1 interface add mon type monitor

I've found the neccesary commands (cmdNewInterface) and attributes, but I am having a very hard time constructing a simple example. Would it be possible to point to, show or guide me towards an example?

This is my current code (which outputs "operation not supported" -- while iw works):

func (c *client) CreateNewInterface(PHY int, ifaceType InterfaceType, name string) error {

	var attrs []netlink.Attribute

	attrs = append(attrs, netlink.Attribute{Type: nl80211.AttrWiphy, Data: []byte(strconv.Itoa(PHY))})
	attrs = append(attrs, netlink.Attribute{Type: nl80211.AttrIftype, Data: []byte(strconv.Itoa(int(ifaceType)))})
	attrs = append(attrs, netlink.Attribute{Type: nl80211.AttrIfname, Data: []byte(name)})

	nlattrs, err := netlink.MarshalAttributes(attrs)
	if err != nil {
		return err
	}

	req := genetlink.Message{
		Header: genetlink.Header{
			Command: nl80211.CmdNewInterface,
			Version: c.familyVersion,
		},
		Data: nlattrs,
	}

	flags := netlink.HeaderFlagsRequest | netlink.HeaderFlagsDump | netlink.HeaderFlagsCreate
	msgs, err := c.c.Execute(req, c.familyID, flags)
	if err != nil {
		fmt.Println("this outputs: ***operation not supported***")
		return err
	}

	if err := c.checkMessages(msgs, nl80211.CmdNewInterface); err != nil {
		return err
	}

	return nil
}

Any help or guidance is highly appreciated -- apologies for potential misunderstandings
Best,
Henrik

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions