ipvlan.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. IPVLAN Driver HOWTO
  2. Initial Release:
  3. Mahesh Bandewar <maheshb AT google.com>
  4. 1. Introduction:
  5. This is conceptually very similar to the macvlan driver with one major
  6. exception of using L3 for mux-ing /demux-ing among slaves. This property makes
  7. the master device share the L2 with it's slave devices. I have developed this
  8. driver in conjuntion with network namespaces and not sure if there is use case
  9. outside of it.
  10. 2. Building and Installation:
  11. In order to build the driver, please select the config item CONFIG_IPVLAN.
  12. The driver can be built into the kernel (CONFIG_IPVLAN=y) or as a module
  13. (CONFIG_IPVLAN=m).
  14. 3. Configuration:
  15. There are no module parameters for this driver and it can be configured
  16. using IProute2/ip utility.
  17. ip link add link <master-dev> <slave-dev> type ipvlan mode { l2 | L3 }
  18. e.g. ip link add link ipvl0 eth0 type ipvlan mode l2
  19. 4. Operating modes:
  20. IPvlan has two modes of operation - L2 and L3. For a given master device,
  21. you can select one of these two modes and all slaves on that master will
  22. operate in the same (selected) mode. The RX mode is almost identical except
  23. that in L3 mode the slaves wont receive any multicast / broadcast traffic.
  24. L3 mode is more restrictive since routing is controlled from the other (mostly)
  25. default namespace.
  26. 4.1 L2 mode:
  27. In this mode TX processing happens on the stack instance attached to the
  28. slave device and packets are switched and queued to the master device to send
  29. out. In this mode the slaves will RX/TX multicast and broadcast (if applicable)
  30. as well.
  31. 4.2 L3 mode:
  32. In this mode TX processing upto L3 happens on the stack instance attached
  33. to the slave device and packets are switched to the stack instance of the
  34. master device for the L2 processing and routing from that instance will be
  35. used before packets are queued on the outbound device. In this mode the slaves
  36. will not receive nor can send multicast / broadcast traffic.
  37. 5. What to choose (macvlan vs. ipvlan)?
  38. These two devices are very similar in many regards and the specific use
  39. case could very well define which device to choose. if one of the following
  40. situations defines your use case then you can choose to use ipvlan -
  41. (a) The Linux host that is connected to the external switch / router has
  42. policy configured that allows only one mac per port.
  43. (b) No of virtual devices created on a master exceed the mac capacity and
  44. puts the NIC in promiscous mode and degraded performance is a concern.
  45. (c) If the slave device is to be put into the hostile / untrusted network
  46. namespace where L2 on the slave could be changed / misused.
  47. 6. Example configuration:
  48. +=============================================================+
  49. | Host: host1 |
  50. | |
  51. | +----------------------+ +----------------------+ |
  52. | | NS:ns0 | | NS:ns1 | |
  53. | | | | | |
  54. | | | | | |
  55. | | ipvl0 | | ipvl1 | |
  56. | +----------#-----------+ +-----------#----------+ |
  57. | # # |
  58. | ################################ |
  59. | # eth0 |
  60. +==============================#==============================+
  61. (a) Create two network namespaces - ns0, ns1
  62. ip netns add ns0
  63. ip netns add ns1
  64. (b) Create two ipvlan slaves on eth0 (master device)
  65. ip link add link eth0 ipvl0 type ipvlan mode l2
  66. ip link add link eth0 ipvl1 type ipvlan mode l2
  67. (c) Assign slaves to the respective network namespaces
  68. ip link set dev ipvl0 netns ns0
  69. ip link set dev ipvl1 netns ns1
  70. (d) Now switch to the namespace (ns0 or ns1) to configure the slave devices
  71. - For ns0
  72. (1) ip netns exec ns0 bash
  73. (2) ip link set dev ipvl0 up
  74. (3) ip link set dev lo up
  75. (4) ip -4 addr add 127.0.0.1 dev lo
  76. (5) ip -4 addr add $IPADDR dev ipvl0
  77. (6) ip -4 route add default via $ROUTER dev ipvl0
  78. - For ns1
  79. (1) ip netns exec ns1 bash
  80. (2) ip link set dev ipvl1 up
  81. (3) ip link set dev lo up
  82. (4) ip -4 addr add 127.0.0.1 dev lo
  83. (5) ip -4 addr add $IPADDR dev ipvl1
  84. (6) ip -4 route add default via $ROUTER dev ipvl1