Merge pull request #331 from nagiesek/LoopbackDsr
Loopback dsr & L2Tunnel
This commit is contained in:
commit
a11cb626b0
@ -77,6 +77,9 @@ func GenerateHnsEndpoint(epInfo *EndpointInfo, n *NetConf) (*hcsshim.HNSEndpoint
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if n.LoopbackDSR {
|
||||||
|
n.ApplyLoopbackDSR(&epInfo.IpAddress)
|
||||||
|
}
|
||||||
if hnsEndpoint == nil {
|
if hnsEndpoint == nil {
|
||||||
hnsEndpoint = &hcsshim.HNSEndpoint{
|
hnsEndpoint = &hcsshim.HNSEndpoint{
|
||||||
Name: epInfo.EndpointName,
|
Name: epInfo.EndpointName,
|
||||||
@ -118,13 +121,7 @@ func GenerateHcnEndpoint(epInfo *EndpointInfo, n *NetConf) (*hcn.HostComputeEndp
|
|||||||
routes := []hcn.Route{
|
routes := []hcn.Route{
|
||||||
{
|
{
|
||||||
NextHop: GetIpString(&epInfo.Gateway),
|
NextHop: GetIpString(&epInfo.Gateway),
|
||||||
DestinationPrefix: func() string {
|
DestinationPrefix: GetDefaultDestinationPrefix(&epInfo.Gateway),
|
||||||
destinationPrefix := "0.0.0.0/0"
|
|
||||||
if ipv6 := epInfo.Gateway.To4(); ipv6 == nil {
|
|
||||||
destinationPrefix = "::/0"
|
|
||||||
}
|
|
||||||
return destinationPrefix
|
|
||||||
}(),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +135,9 @@ func GenerateHcnEndpoint(epInfo *EndpointInfo, n *NetConf) (*hcn.HostComputeEndp
|
|||||||
}
|
}
|
||||||
ipConfigs := []hcn.IpConfig{hcnIpConfig}
|
ipConfigs := []hcn.IpConfig{hcnIpConfig}
|
||||||
|
|
||||||
|
if n.LoopbackDSR {
|
||||||
|
n.ApplyLoopbackDSR(&epInfo.IpAddress)
|
||||||
|
}
|
||||||
hcnEndpoint = &hcn.HostComputeEndpoint{
|
hcnEndpoint = &hcn.HostComputeEndpoint{
|
||||||
SchemaVersion: hcn.Version{Major: 2},
|
SchemaVersion: hcn.Version{Major: 2},
|
||||||
Name: epInfo.EndpointName,
|
Name: epInfo.EndpointName,
|
||||||
|
@ -17,6 +17,9 @@ package hns
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/Microsoft/hcsshim/hcn"
|
"github.com/Microsoft/hcsshim/hcn"
|
||||||
"github.com/buger/jsonparser"
|
"github.com/buger/jsonparser"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
@ -26,9 +29,16 @@ import (
|
|||||||
// NetConf is the CNI spec
|
// NetConf is the CNI spec
|
||||||
type NetConf struct {
|
type NetConf struct {
|
||||||
types.NetConf
|
types.NetConf
|
||||||
|
// ApiVersion is either 1 or 2, which specifies which hns APIs to call
|
||||||
|
ApiVersion int `json:"ApiVersion"`
|
||||||
|
// V2 Api Policies
|
||||||
HcnPolicyArgs []hcn.EndpointPolicy `json:"HcnPolicyArgs,omitempty"`
|
HcnPolicyArgs []hcn.EndpointPolicy `json:"HcnPolicyArgs,omitempty"`
|
||||||
|
// V1 Api Policies
|
||||||
Policies []policy `json:"policies,omitempty"`
|
Policies []policy `json:"policies,omitempty"`
|
||||||
|
// Options to be passed in by the runtime
|
||||||
RuntimeConfig RuntimeConfig `json:"runtimeConfig"`
|
RuntimeConfig RuntimeConfig `json:"runtimeConfig"`
|
||||||
|
// If true, adds a policy to endpoints to support loopback direct server return
|
||||||
|
LoopbackDSR bool `json:"loopbackDSR"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RuntimeDNS struct {
|
type RuntimeDNS struct {
|
||||||
@ -45,6 +55,31 @@ type policy struct {
|
|||||||
Value json.RawMessage `json:"value"`
|
Value json.RawMessage `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDefaultDestinationPrefix(ip *net.IP) string {
|
||||||
|
destinationPrefix := "0.0.0.0/0"
|
||||||
|
if ipv6 := ip.To4(); ipv6 == nil {
|
||||||
|
destinationPrefix = "::/0"
|
||||||
|
}
|
||||||
|
return destinationPrefix
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *NetConf) ApplyLoopbackDSR(ip *net.IP) {
|
||||||
|
value := fmt.Sprintf(`"Destinations" : ["%s"]`, ip.String())
|
||||||
|
if n.ApiVersion == 2 {
|
||||||
|
hcnLoopbackRoute := hcn.EndpointPolicy{
|
||||||
|
Type: "OutBoundNAT",
|
||||||
|
Settings: []byte(fmt.Sprintf("{%s}", value)),
|
||||||
|
}
|
||||||
|
n.HcnPolicyArgs = append(n.HcnPolicyArgs, hcnLoopbackRoute)
|
||||||
|
} else {
|
||||||
|
hnsLoopbackRoute := policy{
|
||||||
|
Name: "EndpointPolicy",
|
||||||
|
Value: []byte(fmt.Sprintf(`{"Type": "OutBoundNAT", %s}`, value)),
|
||||||
|
}
|
||||||
|
n.Policies = append(n.Policies, hnsLoopbackRoute)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If runtime dns values are there use that else use cni conf supplied dns
|
// If runtime dns values are there use that else use cni conf supplied dns
|
||||||
func (n *NetConf) GetDNS() types.DNS {
|
func (n *NetConf) GetDNS() types.DNS {
|
||||||
dnsResult := n.DNS
|
dnsResult := n.DNS
|
||||||
|
@ -32,7 +32,8 @@ With win-bridge plugin, all containers (on the same host) are plugged into an L2
|
|||||||
"NeedEncap": true
|
"NeedEncap": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
].
|
],
|
||||||
|
"loopbackDSR": true,
|
||||||
"capabilities": {
|
"capabilities": {
|
||||||
"dns": true
|
"dns": true
|
||||||
}
|
}
|
||||||
@ -51,5 +52,6 @@ With win-bridge plugin, all containers (on the same host) are plugged into an L2
|
|||||||
* `ipam` (dictionary, optional): IPAM configuration to be used for this network.
|
* `ipam` (dictionary, optional): IPAM configuration to be used for this network.
|
||||||
* `Policies` (list, optional): List of hns policies to be used (only used when ApiVersion is < 2).
|
* `Policies` (list, optional): List of hns policies to be used (only used when ApiVersion is < 2).
|
||||||
* `HcnPolicyArgs` (list, optional): List of hcn policies to be used (only used when ApiVersion is 2).
|
* `HcnPolicyArgs` (list, optional): List of hcn policies to be used (only used when ApiVersion is 2).
|
||||||
* `capabilities` (dictionary, optional): runtime capabilities to enable.
|
* `loopbackDSR` (bool, optional): If true, will add a policy to allow the interface to support loopback direct server return.
|
||||||
* `dns` (boolean, optional): if true will take the dns config supplied by the runtime and override other settings.
|
* `capabilities` (dictionary, optional): Runtime capabilities to enable.
|
||||||
|
* `dns` (boolean, optional): If true, will take the dns config supplied by the runtime and override other settings.
|
@ -39,6 +39,7 @@
|
|||||||
"NeedEncap":true
|
"NeedEncap":true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"loopbackDSR": true
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,6 +17,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -38,7 +39,6 @@ type NetConf struct {
|
|||||||
hns.NetConf
|
hns.NetConf
|
||||||
|
|
||||||
IPMasqNetwork string `json:"ipMasqNetwork,omitempty"`
|
IPMasqNetwork string `json:"ipMasqNetwork,omitempty"`
|
||||||
ApiVersion int `json:"ApiVersion"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -103,7 +103,7 @@ func cmdHnsAdd(args *skel.CmdArgs, n *NetConf) (*current.Result, error) {
|
|||||||
return nil, fmt.Errorf("network %v not found", networkName)
|
return nil, fmt.Errorf("network %v not found", networkName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.EqualFold(hnsNetwork.Type, "L2Bridge") {
|
if !strings.EqualFold(hnsNetwork.Type, "L2Bridge") && !strings.EqualFold(hnsNetwork.Type, "L2Tunnel") {
|
||||||
return nil, fmt.Errorf("network %v is of an unexpected type: %v", networkName, hnsNetwork.Type)
|
return nil, fmt.Errorf("network %v is of an unexpected type: %v", networkName, hnsNetwork.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ func cmdHcnAdd(args *skel.CmdArgs, n *NetConf) (*current.Result, error) {
|
|||||||
return nil, fmt.Errorf("network %v not found", networkName)
|
return nil, fmt.Errorf("network %v not found", networkName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if hcnNetwork.Type != hcn.L2Bridge {
|
if hcnNetwork.Type != hcn.L2Bridge && hcnNetwork.Type != hcn.L2Tunnel {
|
||||||
return nil, fmt.Errorf("network %v is of unexpected type: %v", networkName, hcnNetwork.Type)
|
return nil, fmt.Errorf("network %v is of unexpected type: %v", networkName, hcnNetwork.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@ With win-overlay plugin, all containers (on the same host) are plugged into an O
|
|||||||
"ipam": {
|
"ipam": {
|
||||||
"type": "host-local",
|
"type": "host-local",
|
||||||
"subnet": "10.10.0.0/16"
|
"subnet": "10.10.0.0/16"
|
||||||
}
|
},
|
||||||
|
"loopbackDSR": true,
|
||||||
"capabilites": {
|
"capabilites": {
|
||||||
"dns": true
|
"dns": true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -33,5 +33,6 @@ With win-overlay plugin, all containers (on the same host) are plugged into an O
|
|||||||
* `endpointMacPrefix` (string, optional): set to the MAC prefix configured for Flannel.
|
* `endpointMacPrefix` (string, optional): set to the MAC prefix configured for Flannel.
|
||||||
* `Policies` (list, optional): List of hns policies to be used.
|
* `Policies` (list, optional): List of hns policies to be used.
|
||||||
* `ipam` (dictionary, required): IPAM configuration to be used for this network.
|
* `ipam` (dictionary, required): IPAM configuration to be used for this network.
|
||||||
|
* `loopbackDSR` (bool, optional): If true, will add a policy to allow the interface to support loopback direct server return.
|
||||||
* `capabilities` (dictionary, optional): runtime capabilities to be parsed and injected by runtime.
|
* `capabilities` (dictionary, optional): runtime capabilities to be parsed and injected by runtime.
|
||||||
* `dns` (boolean, optional): if true will take the dns config supplied by the runtime and override other settings.
|
* `dns` (boolean, optional): If true, will take the dns config supplied by the runtime and override other settings.
|
@ -17,6 +17,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -118,7 +119,9 @@ func cmdAdd(args *skel.CmdArgs) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result.DNS = n.GetDNS()
|
result.DNS = n.GetDNS()
|
||||||
|
if n.LoopbackDSR {
|
||||||
|
n.ApplyLoopbackDSR(&ipAddr)
|
||||||
|
}
|
||||||
hnsEndpoint := &hcsshim.HNSEndpoint{
|
hnsEndpoint := &hcsshim.HNSEndpoint{
|
||||||
Name: epName,
|
Name: epName,
|
||||||
VirtualNetwork: hnsNetwork.Id,
|
VirtualNetwork: hnsNetwork.Id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user