ipvlan.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 conjunction 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 | l3s }
  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 up to 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. 4.3 L3S mode:
  38. This is very similar to the L3 mode except that iptables (conn-tracking)
  39. works in this mode and hence it is L3-symmetric (L3s). This will have slightly less
  40. performance but that shouldn't matter since you are choosing this mode over plain-L3
  41. mode to make conn-tracking work.
  42. 5. What to choose (macvlan vs. ipvlan)?
  43. These two devices are very similar in many regards and the specific use
  44. case could very well define which device to choose. if one of the following
  45. situations defines your use case then you can choose to use ipvlan -
  46. (a) The Linux host that is connected to the external switch / router has
  47. policy configured that allows only one mac per port.
  48. (b) No of virtual devices created on a master exceed the mac capacity and
  49. puts the NIC in promiscuous mode and degraded performance is a concern.
  50. (c) If the slave device is to be put into the hostile / untrusted network
  51. namespace where L2 on the slave could be changed / misused.
  52. 6. Example configuration:
  53. +=============================================================+
  54. | Host: host1 |
  55. | |
  56. | +----------------------+ +----------------------+ |
  57. | | NS:ns0 | | NS:ns1 | |
  58. | | | | | |
  59. | | | | | |
  60. | | ipvl0 | | ipvl1 | |
  61. | +----------#-----------+ +-----------#----------+ |
  62. | # # |
  63. | ################################ |
  64. | # eth0 |
  65. +==============================#==============================+
  66. (a) Create two network namespaces - ns0, ns1
  67. ip netns add ns0
  68. ip netns add ns1
  69. (b) Create two ipvlan slaves on eth0 (master device)
  70. ip link add link eth0 ipvl0 type ipvlan mode l2
  71. ip link add link eth0 ipvl1 type ipvlan mode l2
  72. (c) Assign slaves to the respective network namespaces
  73. ip link set dev ipvl0 netns ns0
  74. ip link set dev ipvl1 netns ns1
  75. (d) Now switch to the namespace (ns0 or ns1) to configure the slave devices
  76. - For ns0
  77. (1) ip netns exec ns0 bash
  78. (2) ip link set dev ipvl0 up
  79. (3) ip link set dev lo up
  80. (4) ip -4 addr add 127.0.0.1 dev lo
  81. (5) ip -4 addr add $IPADDR dev ipvl0
  82. (6) ip -4 route add default via $ROUTER dev ipvl0
  83. - For ns1
  84. (1) ip netns exec ns1 bash
  85. (2) ip link set dev ipvl1 up
  86. (3) ip link set dev lo up
  87. (4) ip -4 addr add 127.0.0.1 dev lo
  88. (5) ip -4 addr add $IPADDR dev ipvl1
  89. (6) ip -4 route add default via $ROUTER dev ipvl1