Multiple NICs with netgraph

I needed to simulate multiple PPPoE clients using one NIC. After googling, I was quite convinced that I could do it through netgraph. After more googling, I found this and this and this, which made me come up with the set of commands - found below - to create multiple virtual NICs, each having unique MAC addresses.

host1# kldload ng_ether
host1# kldload ng_eiface
host1# kldload ng_brdige
host1# ifconfig xl0 delete
host1# ifconfig xl0 down
host1# ngctl
Available commands:
config get or set configuration of node at
connect Connects hook of the node at to
debug Get/set debugging verbosity level
dot Produce a GraphViz (.dot) of the entire netgraph.
help Show command summary or get more help on a specific command
list Show information about all nodes
mkpeer Create and connect a new node to the node at "path"
msg Send a netgraph control message to the node at "path"
name Assign name to the node at
read Read and execute commands from a file
rmhook Disconnect hook "hook" of the node at "path"
show Show information about the node at
shutdown Shutdown the node at
status Get human readable status information from the node at
types Show information about all installed node types
write Send a data packet down the hook named by "hook".
quit Exit program
+ mkpeer xl0: bridge lower link0
+ name xl0:lower bnet0
+ mkpeer bnet0: eiface link1
+ name bnet0:link1 vif0
+ ngctl msg xl0: setautosrc 0
+ ngctl msg xl0: setpromisc 1
+ quit
host1# ifconfig ngeth0 link 00:00:00:00:00:0F
host1# ifconfig ngeth0 up
host1# ifconfig xl0 up

I used my xl0 interface as the parent interface the virtual interface (ngeth0). Doing an ifconfig would show the following:
host1# ifconfig
sis0: flags=8843 mtu 1500
options=8
inet6 fe80::211:d8ff:fe79:f0%sis0 prefixlen 64 scopeid 0x1
inet 10.3.1.143 netmask 0xfff00000 broadcast 10.15.255.255
inet6 fec0:ec8:4008:102:211:d8ff:fe79:f0 prefixlen 64 autoconf
inet6 2001:ec8:4008:102:211:d8ff:fe79:f0 prefixlen 64 autoconf
ether 00:11:d8:79:00:f0
media: Ethernet autoselect (100baseTX )
status: active
xl0: flags=8943 mtu 1500
options=9
inet6 fe80::210:5aff:fe9d:5ea9%xl0 prefixlen 64 scopeid 0x2
ether 00:10:5a:9d:5e:a9
media: Ethernet autoselect (100baseTX )
status: active
lo0: flags=8049 mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
inet 127.0.0.1 netmask 0xff000000
pfsync0: flags=0<> mtu 2020
syncpeer: 224.0.0.240 maxupd: 128
pflog0: flags=0<> mtu 33208
ngeth0: flags=8843 mtu 1500
inet6 fe80::200:ff:fe00:f%ngeth0 prefixlen 64 scopeid 0x6
ether 00:00:00:00:00:0f
host1#
Caveats:
  1. The default limit to the number of virtual interfaces - ngeth(N) - interfaces that can be attched to the netgraph bridge(bnet0) is 31.
  2. If you do this, you cannot assign an IP Address to the physical interface, xl0 in my example.
  3. AFAIK, netgraph is only found in FreeBSD.

No comments: