@@ -36,26 +36,44 @@ func installEbtables() {
3636// SetSnatForInterface sets a MAC SNAT rule for an interface.
3737func SetSnatForInterface (interfaceName string , macAddress net.HardwareAddr , action string ) error {
3838 command := fmt .Sprintf (
39- "ebtables -t nat %s POSTROUTING -o %s -j snat --to-src %s --snat-arp" ,
39+ "ebtables -t nat %s POSTROUTING -s unicast - o %s -j snat --to-src %s --snat-arp --snat-target ACCEPT " ,
4040 action , interfaceName , macAddress .String ())
4141
4242 return executeShellCommand (command )
4343}
4444
45+ // SetArpReply sets an ARP reply rule for the given target IP address and MAC address.
46+ func SetArpReply (ipAddress net.IP , macAddress net.HardwareAddr , action string ) error {
47+ command := fmt .Sprintf (
48+ "ebtables -t nat %s PREROUTING -p ARP --arp-ip-dst %s -j arpreply --arpreply-mac %s --arpreply-target DROP" ,
49+ action , ipAddress , macAddress .String ())
50+
51+ return executeShellCommand (command )
52+ }
53+
4554// SetDnatForArpReplies sets a MAC DNAT rule for ARP replies received on an interface.
4655func SetDnatForArpReplies (interfaceName string , action string ) error {
4756 command := fmt .Sprintf (
48- "ebtables -t nat %s PREROUTING -p ARP -i %s -j dnat --to-dst ff:ff:ff:ff:ff:ff" ,
57+ "ebtables -t nat %s PREROUTING -p ARP -i %s -j dnat --to-dst ff:ff:ff:ff:ff:ff --dnat-target ACCEPT " ,
4958 action , interfaceName )
5059
5160 return executeShellCommand (command )
5261}
5362
63+ // SetVepaMode sets the VEPA mode for an interface.
64+ func SetVepaMode (upstreamIfName string , upstreamMacAddress string , action string ) error {
65+ command := fmt .Sprintf (
66+ "ebtables -t nat %s PREROUTING -i ! %s -j dnat --to-dst %s --dnat-target ACCEPT" ,
67+ action , upstreamIfName , upstreamMacAddress )
68+
69+ return executeShellCommand (command )
70+ }
71+
5472// SetDnatForIPAddress sets a MAC DNAT rule for an IP address.
55- func SetDnatForIPAddress (ipAddress net.IP , macAddress net.HardwareAddr , action string ) error {
73+ func SetDnatForIPAddress (interfaceName string , ipAddress net.IP , macAddress net.HardwareAddr , action string ) error {
5674 command := fmt .Sprintf (
57- "ebtables -t nat %s PREROUTING -p IPv4 -- ip-dst %s -j dnat --to-dst %s" ,
58- action , ipAddress .String (), macAddress .String ())
75+ "ebtables -t nat %s PREROUTING -p IPv4 -i %s -- ip-dst %s -j dnat --to-dst %s --dnat-target ACCEPT " ,
76+ action , interfaceName , ipAddress .String (), macAddress .String ())
5977
6078 return executeShellCommand (command )
6179}
0 commit comments