-
Notifications
You must be signed in to change notification settings - Fork 260
Added Host NC communication support in Linux #374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2c88f49
591b379
0cd9e3b
d584f3e
6e144d5
1b51cb9
686013c
963b8f4
2af49dd
a15e9e3
ba62b81
66f0a5b
8b9f318
1b6c562
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| package iptables | ||
|
|
||
| // This package contains wrapper functions to program iptables rules | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/Azure/azure-container-networking/log" | ||
| "github.com/Azure/azure-container-networking/platform" | ||
| ) | ||
|
|
||
| // cni iptable chains | ||
| const ( | ||
| CNIInputChain = "AZURECNIINPUT" | ||
| CNIOutputChain = "AZURECNIOUTPUT" | ||
| ) | ||
|
|
||
| // standard iptable chains | ||
| const ( | ||
| Input = "INPUT" | ||
| Output = "OUTPUT" | ||
| Forward = "FORWARD" | ||
| Prerouting = "PREROUTING" | ||
| Postrouting = "POSTROUTING" | ||
| ) | ||
|
|
||
| // Standard Table names | ||
| const ( | ||
| Filter = "filter" | ||
| Nat = "nat" | ||
| ) | ||
|
|
||
| // target | ||
| const ( | ||
| Accept = "ACCEPT" | ||
| Drop = "DROP" | ||
| Masquerade = "MASQUERADE" | ||
| ) | ||
|
|
||
| // actions | ||
| const ( | ||
| Insert = "I" | ||
| Append = "A" | ||
| Delete = "D" | ||
| ) | ||
|
|
||
| // states | ||
| const ( | ||
| Established = "ESTABLISHED" | ||
| Related = "RELATED" | ||
| ) | ||
|
|
||
| const ( | ||
| iptables = "iptables" | ||
| lockTimeout = 60 | ||
| ) | ||
|
|
||
| // Run iptables command | ||
| func runCmd(params string) error { | ||
| cmd := fmt.Sprintf("%s -w %d %s", iptables, lockTimeout, params) | ||
| if _, err := platform.ExecuteCommand(cmd); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // check if iptable chain alreay exists | ||
| func ChainExists(tableName, chainName string) bool { | ||
| params := fmt.Sprintf("-t %s -L %s", tableName, chainName) | ||
| if err := runCmd(params); err != nil { | ||
| return false | ||
| } | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| // create new iptable chain under specified table name | ||
| func CreateChain(tableName, chainName string) error { | ||
| var err error | ||
|
|
||
| if !ChainExists(tableName, chainName) { | ||
| params := fmt.Sprintf("-t %s -N %s", tableName, chainName) | ||
| err = runCmd(params) | ||
| } else { | ||
| log.Printf("%s Chain exists in table %s", chainName, tableName) | ||
| } | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| // check if iptable rule alreay exists | ||
| func RuleExists(tableName, chainName, match, target string) bool { | ||
| params := fmt.Sprintf("-t %s -C %s %s -j %s", tableName, chainName, match, target) | ||
| if err := runCmd(params); err != nil { | ||
| return false | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| // Insert iptable rule at beginning of iptable chain | ||
| func InsertIptableRule(tableName, chainName, match, target string) error { | ||
| if RuleExists(tableName, chainName, match, target) { | ||
| log.Printf("Rule already exists") | ||
| return nil | ||
| } | ||
|
|
||
| params := fmt.Sprintf("-t %s -I %s 1 %s -j %s", tableName, chainName, match, target) | ||
| return runCmd(params) | ||
| } | ||
|
|
||
| // Append iptable rule at end of iptable chain | ||
| func AppendIptableRule(tableName, chainName, match, target string) error { | ||
| if RuleExists(tableName, chainName, match, target) { | ||
| log.Printf("Rule already exists") | ||
| return nil | ||
| } | ||
|
|
||
| params := fmt.Sprintf("-t %s -A %s %s -j %s", tableName, chainName, match, target) | ||
| return runCmd(params) | ||
| } | ||
|
|
||
| // Delete matched iptable rule | ||
| func DeleteIptableRule(tableName, chainName, match, target string) error { | ||
| params := fmt.Sprintf("-t %s -D %s %s -j %s", tableName, chainName, match, target) | ||
| return runCmd(params) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,50 +17,55 @@ const ( | |
|
|
||
| // Endpoint represents a container network interface. | ||
| type endpoint struct { | ||
| Id string | ||
| HnsId string `json:",omitempty"` | ||
| SandboxKey string | ||
| IfName string | ||
| HostIfName string | ||
| MacAddress net.HardwareAddr | ||
| InfraVnetIP net.IPNet | ||
| IPAddresses []net.IPNet | ||
| Gateways []net.IP | ||
| DNS DNSInfo | ||
| Routes []RouteInfo | ||
| VlanID int | ||
| EnableSnatOnHost bool | ||
| EnableInfraVnet bool | ||
| EnableMultitenancy bool | ||
| NetworkNameSpace string `json:",omitempty"` | ||
| ContainerID string | ||
| PODName string `json:",omitempty"` | ||
| PODNameSpace string `json:",omitempty"` | ||
| InfraVnetAddressSpace string `json:",omitempty"` | ||
| Id string | ||
| HnsId string `json:",omitempty"` | ||
| SandboxKey string | ||
| IfName string | ||
| HostIfName string | ||
| MacAddress net.HardwareAddr | ||
| InfraVnetIP net.IPNet | ||
| LocalIP string | ||
| IPAddresses []net.IPNet | ||
| Gateways []net.IP | ||
| DNS DNSInfo | ||
| Routes []RouteInfo | ||
| VlanID int | ||
| EnableSnatOnHost bool | ||
| EnableInfraVnet bool | ||
| EnableMultitenancy bool | ||
| AllowInboundFromHostToNC bool | ||
| AllowInboundFromNCToHost bool | ||
| NetworkNameSpace string `json:",omitempty"` | ||
| ContainerID string | ||
| PODName string `json:",omitempty"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PodName or Podname
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i didn't change this..so not changing it |
||
| PODNameSpace string `json:",omitempty"` | ||
| InfraVnetAddressSpace string `json:",omitempty"` | ||
| } | ||
|
|
||
| // EndpointInfo contains read-only information about an endpoint. | ||
| type EndpointInfo struct { | ||
| Id string | ||
| ContainerID string | ||
| NetNsPath string | ||
| IfName string | ||
| SandboxKey string | ||
| IfIndex int | ||
| MacAddress net.HardwareAddr | ||
| DNS DNSInfo | ||
| IPAddresses []net.IPNet | ||
| InfraVnetIP net.IPNet | ||
| Routes []RouteInfo | ||
| Policies []policy.Policy | ||
| Gateways []net.IP | ||
| EnableSnatOnHost bool | ||
| EnableInfraVnet bool | ||
| EnableMultiTenancy bool | ||
| PODName string | ||
| PODNameSpace string | ||
| Data map[string]interface{} | ||
| InfraVnetAddressSpace string | ||
| Id string | ||
| ContainerID string | ||
| NetNsPath string | ||
| IfName string | ||
| SandboxKey string | ||
| IfIndex int | ||
| MacAddress net.HardwareAddr | ||
| DNS DNSInfo | ||
| IPAddresses []net.IPNet | ||
| InfraVnetIP net.IPNet | ||
| Routes []RouteInfo | ||
| Policies []policy.Policy | ||
| Gateways []net.IP | ||
| EnableSnatOnHost bool | ||
| EnableInfraVnet bool | ||
| EnableMultiTenancy bool | ||
| AllowInboundFromHostToNC bool | ||
| AllowInboundFromNCToHost bool | ||
| PODName string | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PodName or Podname
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i didn't change this..so not changing it |
||
| PODNameSpace string | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PodNamespace
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i didn't change this..so not changing it |
||
| Data map[string]interface{} | ||
| InfraVnetAddressSpace string | ||
| SkipHotAttachEp bool | ||
| } | ||
|
|
||
|
|
@@ -183,22 +188,24 @@ func podNameMatches(source string, actualValue string, doExactMatch bool) bool { | |
| // GetInfo returns information about the endpoint. | ||
| func (ep *endpoint) getInfo() *EndpointInfo { | ||
| info := &EndpointInfo{ | ||
| Id: ep.Id, | ||
| IPAddresses: ep.IPAddresses, | ||
| InfraVnetIP: ep.InfraVnetIP, | ||
| Data: make(map[string]interface{}), | ||
| MacAddress: ep.MacAddress, | ||
| SandboxKey: ep.SandboxKey, | ||
| IfIndex: 0, // Azure CNI supports only one interface | ||
| DNS: ep.DNS, | ||
| EnableSnatOnHost: ep.EnableSnatOnHost, | ||
| EnableInfraVnet: ep.EnableInfraVnet, | ||
| EnableMultiTenancy: ep.EnableMultitenancy, | ||
| IfName: ep.IfName, | ||
| ContainerID: ep.ContainerID, | ||
| NetNsPath: ep.NetworkNameSpace, | ||
| PODName: ep.PODName, | ||
| PODNameSpace: ep.PODNameSpace, | ||
| Id: ep.Id, | ||
| IPAddresses: ep.IPAddresses, | ||
| InfraVnetIP: ep.InfraVnetIP, | ||
| Data: make(map[string]interface{}), | ||
| MacAddress: ep.MacAddress, | ||
| SandboxKey: ep.SandboxKey, | ||
| IfIndex: 0, // Azure CNI supports only one interface | ||
| DNS: ep.DNS, | ||
| EnableSnatOnHost: ep.EnableSnatOnHost, | ||
| EnableInfraVnet: ep.EnableInfraVnet, | ||
| EnableMultiTenancy: ep.EnableMultitenancy, | ||
| AllowInboundFromHostToNC: ep.AllowInboundFromHostToNC, | ||
| AllowInboundFromNCToHost: ep.AllowInboundFromNCToHost, | ||
| IfName: ep.IfName, | ||
| ContainerID: ep.ContainerID, | ||
| NetNsPath: ep.NetworkNameSpace, | ||
| PODName: ep.PODName, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uncaps POD (see comments above) |
||
| PODNameSpace: ep.PODNameSpace, | ||
| } | ||
|
|
||
| for _, route := range ep.Routes { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goformat automatically does that