From 2d0978cf76311a2512b0282b0bf7f60495c73b3b Mon Sep 17 00:00:00 2001 From: Kathryn Baldauf Date: Fri, 9 Jul 2021 11:05:44 -0700 Subject: [PATCH] Add test network agent for ncproxy dev work Signed-off-by: Kathryn Baldauf --- .github/workflows/ci.yml | 2 + .golangci.yml | 10 + .../ncproxy_mock/nodenetsvc_mock.pb.go | 35 + cmd/ncproxy/nodenetsvc/nodenetsvc.pb.go | 1160 +++++++++++++++-- cmd/ncproxy/nodenetsvc/nodenetsvc.proto | 55 +- internal/tools/networkagent/defs.go | 50 + internal/tools/networkagent/main.go | 345 +++++ .../Microsoft/hcsshim/.golangci.yml | 10 + 8 files changed, 1555 insertions(+), 112 deletions(-) create mode 100644 internal/tools/networkagent/defs.go create mode 100644 internal/tools/networkagent/main.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fae15145a0..939f6bb38f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -111,6 +111,7 @@ jobs: - run: go build ./cmd/ncproxy - run: go build ./cmd/dmverity-vhd - run: go build ./internal/tools/grantvmgroupaccess + - run: go build ./internal/tools/networkagent - run: go build ./internal/tools/securitypolicy - run: go build ./internal/tools/uvmboot - run: go build ./internal/tools/zapdir @@ -125,6 +126,7 @@ jobs: device-util.exe wclayer.exe grantvmgroupaccess.exe + networkagent.exe uvmboot.exe zapdir.exe ncproxy.exe diff --git a/.golangci.yml b/.golangci.yml index 16b25be554..728178cff4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -24,6 +24,16 @@ issues: linters: - stylecheck Text: "ST1003:" + + - path: cmd\\ncproxy\\nodenetsvc\\ + linters: + - stylecheck + Text: "ST1003:" + + - path: cmd\\ncproxy_mock\\ + linters: + - stylecheck + Text: "ST1003:" - path: internal\\hcs\\schema2\\ linters: diff --git a/cmd/ncproxy/ncproxy_mock/nodenetsvc_mock.pb.go b/cmd/ncproxy/ncproxy_mock/nodenetsvc_mock.pb.go index 4d2af8586f..56003a8156 100644 --- a/cmd/ncproxy/ncproxy_mock/nodenetsvc_mock.pb.go +++ b/cmd/ncproxy/ncproxy_mock/nodenetsvc_mock.pb.go @@ -76,6 +76,26 @@ func (mr *MockNodeNetworkServiceClientMockRecorder) ConfigureNetworking(ctx, in return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureNetworking", reflect.TypeOf((*MockNodeNetworkServiceClient)(nil).ConfigureNetworking), varargs...) } +// GetHostLocalIpAddress mocks base method. +func (m *MockNodeNetworkServiceClient) GetHostLocalIpAddress(ctx context.Context, in *nodenetsvc.GetHostLocalIpAddressRequest, opts ...grpc.CallOption) (*nodenetsvc.GetHostLocalIpAddressResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetHostLocalIpAddress", varargs...) + ret0, _ := ret[0].(*nodenetsvc.GetHostLocalIpAddressResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetHostLocalIpAddress indicates an expected call of GetHostLocalIpAddress. +func (mr *MockNodeNetworkServiceClientMockRecorder) GetHostLocalIpAddress(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHostLocalIpAddress", reflect.TypeOf((*MockNodeNetworkServiceClient)(nil).GetHostLocalIpAddress), varargs...) +} + // PingNodeNetworkService mocks base method. func (m *MockNodeNetworkServiceClient) PingNodeNetworkService(ctx context.Context, in *nodenetsvc.PingNodeNetworkServiceRequest, opts ...grpc.CallOption) (*nodenetsvc.PingNodeNetworkServiceResponse, error) { m.ctrl.T.Helper() @@ -149,6 +169,21 @@ func (mr *MockNodeNetworkServiceServerMockRecorder) ConfigureNetworking(arg0, ar return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureNetworking", reflect.TypeOf((*MockNodeNetworkServiceServer)(nil).ConfigureNetworking), arg0, arg1) } +// GetHostLocalIpAddress mocks base method. +func (m *MockNodeNetworkServiceServer) GetHostLocalIpAddress(arg0 context.Context, arg1 *nodenetsvc.GetHostLocalIpAddressRequest) (*nodenetsvc.GetHostLocalIpAddressResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetHostLocalIpAddress", arg0, arg1) + ret0, _ := ret[0].(*nodenetsvc.GetHostLocalIpAddressResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetHostLocalIpAddress indicates an expected call of GetHostLocalIpAddress. +func (mr *MockNodeNetworkServiceServerMockRecorder) GetHostLocalIpAddress(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHostLocalIpAddress", reflect.TypeOf((*MockNodeNetworkServiceServer)(nil).GetHostLocalIpAddress), arg0, arg1) +} + // PingNodeNetworkService mocks base method. func (m *MockNodeNetworkServiceServer) PingNodeNetworkService(arg0 context.Context, arg1 *nodenetsvc.PingNodeNetworkServiceRequest) (*nodenetsvc.PingNodeNetworkServiceResponse, error) { m.ctrl.T.Helper() diff --git a/cmd/ncproxy/nodenetsvc/nodenetsvc.pb.go b/cmd/ncproxy/nodenetsvc/nodenetsvc.pb.go index 61a2a8beed..8fa3ec1b0e 100644 --- a/cmd/ncproxy/nodenetsvc/nodenetsvc.pb.go +++ b/cmd/ncproxy/nodenetsvc/nodenetsvc.pb.go @@ -129,7 +129,7 @@ func (m *ConfigureNetworkingResponse) XXX_DiscardUnknown() { var xxx_messageInfo_ConfigureNetworkingResponse proto.InternalMessageInfo type PingNodeNetworkServiceRequest struct { - PingRequestMessage string `protobuf:"bytes,1,opt,name=pingRequestMessage,proto3" json:"pingRequestMessage,omitempty"` + PingRequestMessage string `protobuf:"bytes,1,opt,name=ping_request_message,json=pingRequestMessage,proto3" json:"ping_request_message,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -168,7 +168,7 @@ func (m *PingNodeNetworkServiceRequest) XXX_DiscardUnknown() { var xxx_messageInfo_PingNodeNetworkServiceRequest proto.InternalMessageInfo type PingNodeNetworkServiceResponse struct { - PingResponseMessage string `protobuf:"bytes,1,opt,name=pingResponseMessage,proto3" json:"pingResponseMessage,omitempty"` + PingResponseMessage string `protobuf:"bytes,1,opt,name=ping_response_message,json=pingResponseMessage,proto3" json:"ping_response_message,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -209,7 +209,7 @@ var xxx_messageInfo_PingNodeNetworkServiceResponse proto.InternalMessageInfo type ConfigureContainerNetworkingRequest struct { RequestType RequestType `protobuf:"varint,1,opt,name=request_type,json=requestType,proto3,enum=azure.nodenetworkservice.RequestType" json:"request_type,omitempty"` ContainerID string `protobuf:"bytes,2,opt,name=container_id,json=containerId,proto3" json:"container_id,omitempty"` - NetworkNamespace string `protobuf:"bytes,3,opt,name=network_namespace,json=networkNamespace,proto3" json:"network_namespace,omitempty"` + NetworkNamespaceID string `protobuf:"bytes,3,opt,name=network_namespace_id,json=networkNamespaceId,proto3" json:"network_namespace_id,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -248,12 +248,10 @@ func (m *ConfigureContainerNetworkingRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ConfigureContainerNetworkingRequest proto.InternalMessageInfo type ConfigureContainerNetworkingResponse struct { - Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"` - ResponseJson string `protobuf:"bytes,2,opt,name=response_json,json=responseJson,proto3" json:"response_json,omitempty"` - ErrorJson string `protobuf:"bytes,3,opt,name=error_json,json=errorJson,proto3" json:"error_json,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Interfaces []*ContainerNetworkInterface `protobuf:"bytes,1,rep,name=interfaces,proto3" json:"interfaces,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *ConfigureContainerNetworkingResponse) Reset() { *m = ConfigureContainerNetworkingResponse{} } @@ -288,6 +286,168 @@ func (m *ConfigureContainerNetworkingResponse) XXX_DiscardUnknown() { var xxx_messageInfo_ConfigureContainerNetworkingResponse proto.InternalMessageInfo +type ContainerIPAddress struct { + Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` + Ip string `protobuf:"bytes,3,opt,name=ip,proto3" json:"ip,omitempty"` + PrefixLength string `protobuf:"bytes,4,opt,name=prefix_length,json=prefixLength,proto3" json:"prefix_length,omitempty"` + DefaultGateway string `protobuf:"bytes,5,opt,name=default_gateway,json=defaultGateway,proto3" json:"default_gateway,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ContainerIPAddress) Reset() { *m = ContainerIPAddress{} } +func (*ContainerIPAddress) ProtoMessage() {} +func (*ContainerIPAddress) Descriptor() ([]byte, []int) { + return fileDescriptor_3a65404bd96160d4, []int{6} +} +func (m *ContainerIPAddress) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ContainerIPAddress) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ContainerIPAddress.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ContainerIPAddress) XXX_Merge(src proto.Message) { + xxx_messageInfo_ContainerIPAddress.Merge(m, src) +} +func (m *ContainerIPAddress) XXX_Size() int { + return m.Size() +} +func (m *ContainerIPAddress) XXX_DiscardUnknown() { + xxx_messageInfo_ContainerIPAddress.DiscardUnknown(m) +} + +var xxx_messageInfo_ContainerIPAddress proto.InternalMessageInfo + +type ContainerNetworkInterface struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + MacAddress string `protobuf:"bytes,2,opt,name=mac_address,json=macAddress,proto3" json:"mac_address,omitempty"` + NetworkNamespaceID string `protobuf:"bytes,3,opt,name=network_namespace_id,json=networkNamespaceId,proto3" json:"network_namespace_id,omitempty"` + Ipaddresses []*ContainerIPAddress `protobuf:"bytes,4,rep,name=ipaddresses,proto3" json:"ipaddresses,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ContainerNetworkInterface) Reset() { *m = ContainerNetworkInterface{} } +func (*ContainerNetworkInterface) ProtoMessage() {} +func (*ContainerNetworkInterface) Descriptor() ([]byte, []int) { + return fileDescriptor_3a65404bd96160d4, []int{7} +} +func (m *ContainerNetworkInterface) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ContainerNetworkInterface) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ContainerNetworkInterface.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ContainerNetworkInterface) XXX_Merge(src proto.Message) { + xxx_messageInfo_ContainerNetworkInterface.Merge(m, src) +} +func (m *ContainerNetworkInterface) XXX_Size() int { + return m.Size() +} +func (m *ContainerNetworkInterface) XXX_DiscardUnknown() { + xxx_messageInfo_ContainerNetworkInterface.DiscardUnknown(m) +} + +var xxx_messageInfo_ContainerNetworkInterface proto.InternalMessageInfo + +type GetHostLocalIpAddressRequest struct { + ContainerID string `protobuf:"bytes,1,opt,name=container_id,json=containerId,proto3" json:"container_id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetHostLocalIpAddressRequest) Reset() { *m = GetHostLocalIpAddressRequest{} } +func (*GetHostLocalIpAddressRequest) ProtoMessage() {} +func (*GetHostLocalIpAddressRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_3a65404bd96160d4, []int{8} +} +func (m *GetHostLocalIpAddressRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GetHostLocalIpAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GetHostLocalIpAddressRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GetHostLocalIpAddressRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetHostLocalIpAddressRequest.Merge(m, src) +} +func (m *GetHostLocalIpAddressRequest) XXX_Size() int { + return m.Size() +} +func (m *GetHostLocalIpAddressRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetHostLocalIpAddressRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetHostLocalIpAddressRequest proto.InternalMessageInfo + +type GetHostLocalIpAddressResponse struct { + IpAddr string `protobuf:"bytes,1,opt,name=ip_addr,json=ipAddr,proto3" json:"ip_addr,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetHostLocalIpAddressResponse) Reset() { *m = GetHostLocalIpAddressResponse{} } +func (*GetHostLocalIpAddressResponse) ProtoMessage() {} +func (*GetHostLocalIpAddressResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_3a65404bd96160d4, []int{9} +} +func (m *GetHostLocalIpAddressResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GetHostLocalIpAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GetHostLocalIpAddressResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GetHostLocalIpAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetHostLocalIpAddressResponse.Merge(m, src) +} +func (m *GetHostLocalIpAddressResponse) XXX_Size() int { + return m.Size() +} +func (m *GetHostLocalIpAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GetHostLocalIpAddressResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GetHostLocalIpAddressResponse proto.InternalMessageInfo + func init() { proto.RegisterEnum("azure.nodenetworkservice.RequestType", RequestType_name, RequestType_value) proto.RegisterType((*ConfigureNetworkingRequest)(nil), "azure.nodenetworkservice.ConfigureNetworkingRequest") @@ -296,6 +456,10 @@ func init() { proto.RegisterType((*PingNodeNetworkServiceResponse)(nil), "azure.nodenetworkservice.PingNodeNetworkServiceResponse") proto.RegisterType((*ConfigureContainerNetworkingRequest)(nil), "azure.nodenetworkservice.ConfigureContainerNetworkingRequest") proto.RegisterType((*ConfigureContainerNetworkingResponse)(nil), "azure.nodenetworkservice.ConfigureContainerNetworkingResponse") + proto.RegisterType((*ContainerIPAddress)(nil), "azure.nodenetworkservice.ContainerIPAddress") + proto.RegisterType((*ContainerNetworkInterface)(nil), "azure.nodenetworkservice.ContainerNetworkInterface") + proto.RegisterType((*GetHostLocalIpAddressRequest)(nil), "azure.nodenetworkservice.GetHostLocalIpAddressRequest") + proto.RegisterType((*GetHostLocalIpAddressResponse)(nil), "azure.nodenetworkservice.GetHostLocalIpAddressResponse") } func init() { @@ -303,40 +467,52 @@ func init() { } var fileDescriptor_3a65404bd96160d4 = []byte{ - // 513 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x41, 0x6f, 0xd3, 0x30, - 0x14, 0xae, 0x37, 0x01, 0xeb, 0x6b, 0x81, 0xe2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xef, 0xc6, - 0x83, 0x08, 0x8d, 0x85, 0x15, 0xb2, 0x7e, 0xad, 0x7d, 0xd7, 0x2e, 0xd3, 0x60, 0x67, 0x9b, 0xed, - 0x0d, 0x22, 0x74, 0x6b, 0x72, 0xfc, 0x63, 0xb5, 0xe0, 0x56, 0xa1, 0x36, 0x15, 0x09, 0xae, 0xd0, - 0x7a, 0x0d, 0xad, 0x37, 0x21, 0x0f, 0x3a, 0xc2, 0xcf, 0xd1, 0x5d, 0xcd, 0x98, 0xab, 0xb7, 0x81, - 0x46, 0x63, 0x33, 0x3b, 0xa8, 0x94, 0x17, 0xa0, 0xf6, 0xe0, 0x16, 0x20, 0x96, 0x0b, 0x66, 0x19, - 0xa1, 0xde, 0x92, 0x3e, 0x84, 0xe5, 0x68, 0x42, 0xc2, 0xff, 0x94, 0x45, 0x90, 0x75, 0x42, 0x60, - 0x75, 0x64, 0x62, 0x94, 0xd9, 0x74, 0xd2, 0x67, 0x53, 0x23, 0xf3, 0xa6, 0x36, 0x75, 0x66, 0x0b, - 0xe7, 0x38, 0xb3, 0x07, 0x70, 0x23, 0xa3, 0xef, 0x72, 0xaf, 0x8f, 0x2a, 0xf2, 0x18, 0x1a, 0x8b, - 0x43, 0x57, 0x8d, 0x0c, 0xe8, 0xe4, 0x75, 0xeb, 0x2b, 0x81, 0xb5, 0xd9, 0x96, 0xb2, 0xb4, 0x0c, - 0xb8, 0xa2, 0x12, 0xc6, 0x50, 0xa9, 0xa1, 0x9d, 0x25, 0x37, 0xff, 0xa5, 0xab, 0x70, 0x55, 0x66, - 0xab, 0xba, 0xef, 0x94, 0xe0, 0x5a, 0xa4, 0x5b, 0xcf, 0x8b, 0xaf, 0x94, 0xe0, 0xb4, 0x05, 0x80, - 0x52, 0x0a, 0xa9, 0x57, 0x68, 0x35, 0xd5, 0x61, 0xe5, 0x1f, 0x7c, 0xff, 0x1e, 0xd4, 0x26, 0x32, - 0xa0, 0x55, 0xb8, 0xb4, 0x8b, 0x71, 0x12, 0x35, 0x2a, 0xb4, 0x0e, 0x4b, 0x7b, 0xe8, 0x49, 0x5f, - 0x1c, 0xf1, 0x06, 0x69, 0xff, 0x5c, 0x04, 0x3a, 0x7d, 0xa4, 0xf4, 0x0b, 0x81, 0xe5, 0x82, 0xdb, - 0x45, 0x1f, 0x97, 0x47, 0x5e, 0x3e, 0x28, 0xcd, 0x27, 0x17, 0xec, 0xca, 0x12, 0xfa, 0x41, 0xe0, - 0xf6, 0xac, 0x28, 0xe9, 0xf3, 0x73, 0xf0, 0x96, 0xdf, 0xaa, 0xe6, 0x8b, 0x79, 0xdb, 0x33, 0x7d, - 0xdf, 0x08, 0xdc, 0x2c, 0x1e, 0x09, 0xfa, 0xb4, 0x9c, 0x7a, 0xe6, 0x54, 0x36, 0x9f, 0x5d, 0xbc, - 0x51, 0xab, 0xd9, 0x58, 0x3b, 0x3e, 0x35, 0x2b, 0xbf, 0x4e, 0xcd, 0xca, 0xe7, 0xd4, 0x24, 0xc7, - 0xa9, 0x49, 0x4e, 0x52, 0x93, 0xfc, 0x49, 0x4d, 0xf2, 0x16, 0xc6, 0x4f, 0xde, 0xfe, 0xe5, 0xe1, - 0x9b, 0xf7, 0xe8, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x25, 0xe7, 0xf5, 0xc4, 0x3b, 0x05, 0x00, - 0x00, + // 716 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0xcf, 0x4f, 0x13, 0x4d, + 0x18, 0x66, 0x4a, 0x81, 0x8f, 0xb7, 0xfd, 0x80, 0x0c, 0x3f, 0xbe, 0xfd, 0x2a, 0x14, 0xb2, 0xa0, + 0x12, 0x63, 0x5a, 0x53, 0x54, 0xb8, 0x68, 0x22, 0x90, 0x40, 0x13, 0x68, 0x70, 0xe1, 0xe4, 0xa5, + 0x59, 0x76, 0xa7, 0xdb, 0x89, 0x74, 0x66, 0x9c, 0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0xf7, 0xf5, 0x27, 0x66, 0x92, 0x66, 0x9e, + 0xdc, 0xb0, 0x4a, 0x8b, 0xfb, 0x8a, 0x60, 0xb6, 0xdf, 0x5d, 0xc2, 0xcf, 0xae, 0x81, 0x1b, 0x3f, + 0x72, 0x32, 0xcf, 0x6f, 0x5b, 0xae, 0xf9, 0x7d, 0x42, 0x30, 0xd3, 0x7b, 0x62, 0xe2, 0xd5, 0x78, + 0xe8, 0xbe, 0x63, 0x3b, 0xb3, 0x76, 0xf3, 0x42, 0xcd, 0xe6, 0x23, 0x82, 0xe9, 0x9e, 0x87, 0x05, + 0x3f, 0x8d, 0xc7, 0xec, 0x77, 0x62, 0x33, 0xab, 0x37, 0xae, 0x0b, 0xa9, 0xac, 0x2f, 0x9d, 0x5d, + 0x64, 0x07, 0x7e, 0x5c, 0x64, 0x07, 0xde, 0x37, 0xb3, 0xe8, 0xac, 0x99, 0x45, 0xdf, 0x9a, 0x59, + 0xf4, 0xb3, 0x99, 0x45, 0xaf, 0xa0, 0xfd, 0x3c, 0x1f, 0x0e, 0x07, 0xef, 0xf3, 0xca, 0x9f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xc1, 0xaa, 0xe1, 0x78, 0xe7, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -354,6 +530,7 @@ type NodeNetworkServiceClient interface { ConfigureNetworking(ctx context.Context, in *ConfigureNetworkingRequest, opts ...grpc.CallOption) (*ConfigureNetworkingResponse, error) ConfigureContainerNetworking(ctx context.Context, in *ConfigureContainerNetworkingRequest, opts ...grpc.CallOption) (*ConfigureContainerNetworkingResponse, error) PingNodeNetworkService(ctx context.Context, in *PingNodeNetworkServiceRequest, opts ...grpc.CallOption) (*PingNodeNetworkServiceResponse, error) + GetHostLocalIpAddress(ctx context.Context, in *GetHostLocalIpAddressRequest, opts ...grpc.CallOption) (*GetHostLocalIpAddressResponse, error) } type nodeNetworkServiceClient struct { @@ -391,11 +568,21 @@ func (c *nodeNetworkServiceClient) PingNodeNetworkService(ctx context.Context, i return out, nil } +func (c *nodeNetworkServiceClient) GetHostLocalIpAddress(ctx context.Context, in *GetHostLocalIpAddressRequest, opts ...grpc.CallOption) (*GetHostLocalIpAddressResponse, error) { + out := new(GetHostLocalIpAddressResponse) + err := c.cc.Invoke(ctx, "/azure.nodenetworkservice.NodeNetworkService/GetHostLocalIpAddress", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // NodeNetworkServiceServer is the server API for NodeNetworkService service. type NodeNetworkServiceServer interface { ConfigureNetworking(context.Context, *ConfigureNetworkingRequest) (*ConfigureNetworkingResponse, error) ConfigureContainerNetworking(context.Context, *ConfigureContainerNetworkingRequest) (*ConfigureContainerNetworkingResponse, error) PingNodeNetworkService(context.Context, *PingNodeNetworkServiceRequest) (*PingNodeNetworkServiceResponse, error) + GetHostLocalIpAddress(context.Context, *GetHostLocalIpAddressRequest) (*GetHostLocalIpAddressResponse, error) } func RegisterNodeNetworkServiceServer(s *grpc.Server, srv NodeNetworkServiceServer) { @@ -456,6 +643,24 @@ func _NodeNetworkService_PingNodeNetworkService_Handler(srv interface{}, ctx con return interceptor(ctx, in, info, handler) } +func _NodeNetworkService_GetHostLocalIpAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetHostLocalIpAddressRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(NodeNetworkServiceServer).GetHostLocalIpAddress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/azure.nodenetworkservice.NodeNetworkService/GetHostLocalIpAddress", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(NodeNetworkServiceServer).GetHostLocalIpAddress(ctx, req.(*GetHostLocalIpAddressRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _NodeNetworkService_serviceDesc = grpc.ServiceDesc{ ServiceName: "azure.nodenetworkservice.NodeNetworkService", HandlerType: (*NodeNetworkServiceServer)(nil), @@ -472,6 +677,10 @@ var _NodeNetworkService_serviceDesc = grpc.ServiceDesc{ MethodName: "PingNodeNetworkService", Handler: _NodeNetworkService_PingNodeNetworkService_Handler, }, + { + MethodName: "GetHostLocalIpAddress", + Handler: _NodeNetworkService_GetHostLocalIpAddress_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "github.com/Microsoft/hcsshim/cmd/ncproxy/nodenetsvc/nodenetsvc.proto", @@ -610,11 +819,11 @@ func (m *ConfigureContainerNetworkingRequest) MarshalTo(dAtA []byte) (int, error i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.ContainerID))) i += copy(dAtA[i:], m.ContainerID) } - if len(m.NetworkNamespace) > 0 { + if len(m.NetworkNamespaceID) > 0 { dAtA[i] = 0x1a i++ - i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.NetworkNamespace))) - i += copy(dAtA[i:], m.NetworkNamespace) + i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.NetworkNamespaceID))) + i += copy(dAtA[i:], m.NetworkNamespaceID) } if m.XXX_unrecognized != nil { i += copy(dAtA[i:], m.XXX_unrecognized) @@ -637,27 +846,167 @@ func (m *ConfigureContainerNetworkingResponse) MarshalTo(dAtA []byte) (int, erro _ = i var l int _ = l - if m.Success { - dAtA[i] = 0x8 - i++ - if m.Success { - dAtA[i] = 1 - } else { - dAtA[i] = 0 + if len(m.Interfaces) > 0 { + for _, msg := range m.Interfaces { + dAtA[i] = 0xa + i++ + i = encodeVarintNodenetsvc(dAtA, i, uint64(msg.Size())) + n, err := msg.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n } + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + +func (m *ContainerIPAddress) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ContainerIPAddress) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Version) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.Version))) + i += copy(dAtA[i:], m.Version) + } + if len(m.Ip) > 0 { + dAtA[i] = 0x1a + i++ + i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.Ip))) + i += copy(dAtA[i:], m.Ip) + } + if len(m.PrefixLength) > 0 { + dAtA[i] = 0x22 + i++ + i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.PrefixLength))) + i += copy(dAtA[i:], m.PrefixLength) + } + if len(m.DefaultGateway) > 0 { + dAtA[i] = 0x2a + i++ + i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.DefaultGateway))) + i += copy(dAtA[i:], m.DefaultGateway) + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + +func (m *ContainerNetworkInterface) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ContainerNetworkInterface) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Name) > 0 { + dAtA[i] = 0xa i++ + i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.Name))) + i += copy(dAtA[i:], m.Name) } - if len(m.ResponseJson) > 0 { + if len(m.MacAddress) > 0 { dAtA[i] = 0x12 i++ - i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.ResponseJson))) - i += copy(dAtA[i:], m.ResponseJson) + i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.MacAddress))) + i += copy(dAtA[i:], m.MacAddress) } - if len(m.ErrorJson) > 0 { + if len(m.NetworkNamespaceID) > 0 { dAtA[i] = 0x1a i++ - i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.ErrorJson))) - i += copy(dAtA[i:], m.ErrorJson) + i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.NetworkNamespaceID))) + i += copy(dAtA[i:], m.NetworkNamespaceID) + } + if len(m.Ipaddresses) > 0 { + for _, msg := range m.Ipaddresses { + dAtA[i] = 0x22 + i++ + i = encodeVarintNodenetsvc(dAtA, i, uint64(msg.Size())) + n, err := msg.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n + } + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + +func (m *GetHostLocalIpAddressRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GetHostLocalIpAddressRequest) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.ContainerID) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.ContainerID))) + i += copy(dAtA[i:], m.ContainerID) + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + +func (m *GetHostLocalIpAddressResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GetHostLocalIpAddressResponse) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.IpAddr) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintNodenetsvc(dAtA, i, uint64(len(m.IpAddr))) + i += copy(dAtA[i:], m.IpAddr) } if m.XXX_unrecognized != nil { i += copy(dAtA[i:], m.XXX_unrecognized) @@ -750,7 +1099,7 @@ func (m *ConfigureContainerNetworkingRequest) Size() (n int) { if l > 0 { n += 1 + l + sovNodenetsvc(uint64(l)) } - l = len(m.NetworkNamespace) + l = len(m.NetworkNamespaceID) if l > 0 { n += 1 + l + sovNodenetsvc(uint64(l)) } @@ -766,14 +1115,37 @@ func (m *ConfigureContainerNetworkingResponse) Size() (n int) { } var l int _ = l - if m.Success { - n += 2 + if len(m.Interfaces) > 0 { + for _, e := range m.Interfaces { + l = e.Size() + n += 1 + l + sovNodenetsvc(uint64(l)) + } + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *ContainerIPAddress) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Version) + if l > 0 { + n += 1 + l + sovNodenetsvc(uint64(l)) } - l = len(m.ResponseJson) + l = len(m.Ip) if l > 0 { n += 1 + l + sovNodenetsvc(uint64(l)) } - l = len(m.ErrorJson) + l = len(m.PrefixLength) + if l > 0 { + n += 1 + l + sovNodenetsvc(uint64(l)) + } + l = len(m.DefaultGateway) if l > 0 { n += 1 + l + sovNodenetsvc(uint64(l)) } @@ -783,22 +1155,84 @@ func (m *ConfigureContainerNetworkingResponse) Size() (n int) { return n } -func sovNodenetsvc(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } +func (m *ContainerNetworkInterface) Size() (n int) { + if m == nil { + return 0 } - return n -} -func sozNodenetsvc(x uint64) (n int) { - return sovNodenetsvc(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *ConfigureNetworkingRequest) String() string { - if this == nil { - return "nil" + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovNodenetsvc(uint64(l)) + } + l = len(m.MacAddress) + if l > 0 { + n += 1 + l + sovNodenetsvc(uint64(l)) + } + l = len(m.NetworkNamespaceID) + if l > 0 { + n += 1 + l + sovNodenetsvc(uint64(l)) + } + if len(m.Ipaddresses) > 0 { + for _, e := range m.Ipaddresses { + l = e.Size() + n += 1 + l + sovNodenetsvc(uint64(l)) + } + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *GetHostLocalIpAddressRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ContainerID) + if l > 0 { + n += 1 + l + sovNodenetsvc(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *GetHostLocalIpAddressResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.IpAddr) + if l > 0 { + n += 1 + l + sovNodenetsvc(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func sovNodenetsvc(x uint64) (n int) { + for { + n++ + x >>= 7 + if x == 0 { + break + } + } + return n +} +func sozNodenetsvc(x uint64) (n int) { + return sovNodenetsvc(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *ConfigureNetworkingRequest) String() string { + if this == nil { + return "nil" } s := strings.Join([]string{`&ConfigureNetworkingRequest{`, `ContainerID:` + fmt.Sprintf("%v", this.ContainerID) + `,`, @@ -847,7 +1281,7 @@ func (this *ConfigureContainerNetworkingRequest) String() string { s := strings.Join([]string{`&ConfigureContainerNetworkingRequest{`, `RequestType:` + fmt.Sprintf("%v", this.RequestType) + `,`, `ContainerID:` + fmt.Sprintf("%v", this.ContainerID) + `,`, - `NetworkNamespace:` + fmt.Sprintf("%v", this.NetworkNamespace) + `,`, + `NetworkNamespaceID:` + fmt.Sprintf("%v", this.NetworkNamespaceID) + `,`, `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, `}`, }, "") @@ -858,9 +1292,57 @@ func (this *ConfigureContainerNetworkingResponse) String() string { return "nil" } s := strings.Join([]string{`&ConfigureContainerNetworkingResponse{`, - `Success:` + fmt.Sprintf("%v", this.Success) + `,`, - `ResponseJson:` + fmt.Sprintf("%v", this.ResponseJson) + `,`, - `ErrorJson:` + fmt.Sprintf("%v", this.ErrorJson) + `,`, + `Interfaces:` + strings.Replace(fmt.Sprintf("%v", this.Interfaces), "ContainerNetworkInterface", "ContainerNetworkInterface", 1) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} +func (this *ContainerIPAddress) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ContainerIPAddress{`, + `Version:` + fmt.Sprintf("%v", this.Version) + `,`, + `Ip:` + fmt.Sprintf("%v", this.Ip) + `,`, + `PrefixLength:` + fmt.Sprintf("%v", this.PrefixLength) + `,`, + `DefaultGateway:` + fmt.Sprintf("%v", this.DefaultGateway) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} +func (this *ContainerNetworkInterface) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ContainerNetworkInterface{`, + `Name:` + fmt.Sprintf("%v", this.Name) + `,`, + `MacAddress:` + fmt.Sprintf("%v", this.MacAddress) + `,`, + `NetworkNamespaceID:` + fmt.Sprintf("%v", this.NetworkNamespaceID) + `,`, + `Ipaddresses:` + strings.Replace(fmt.Sprintf("%v", this.Ipaddresses), "ContainerIPAddress", "ContainerIPAddress", 1) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} +func (this *GetHostLocalIpAddressRequest) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&GetHostLocalIpAddressRequest{`, + `ContainerID:` + fmt.Sprintf("%v", this.ContainerID) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} +func (this *GetHostLocalIpAddressResponse) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&GetHostLocalIpAddressResponse{`, + `IpAddr:` + fmt.Sprintf("%v", this.IpAddr) + `,`, `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, `}`, }, "") @@ -1287,7 +1769,7 @@ func (m *ConfigureContainerNetworkingRequest) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NetworkNamespace", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field NetworkNamespaceID", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1315,7 +1797,7 @@ func (m *ConfigureContainerNetworkingRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.NetworkNamespace = string(dAtA[iNdEx:postIndex]) + m.NetworkNamespaceID = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -1372,10 +1854,10 @@ func (m *ConfigureContainerNetworkingResponse) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Success", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Interfaces", wireType) } - var v int + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowNodenetsvc @@ -1385,15 +1867,83 @@ func (m *ConfigureContainerNetworkingResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - m.Success = bool(v != 0) - case 2: + if msglen < 0 { + return ErrInvalidLengthNodenetsvc + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthNodenetsvc + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Interfaces = append(m.Interfaces, &ContainerNetworkInterface{}) + if err := m.Interfaces[len(m.Interfaces)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipNodenetsvc(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthNodenetsvc + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthNodenetsvc + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ContainerIPAddress) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodenetsvc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ContainerIPAddress: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ContainerIPAddress: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ResponseJson", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1421,11 +1971,431 @@ func (m *ConfigureContainerNetworkingResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.ResponseJson = string(dAtA[iNdEx:postIndex]) + m.Version = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ErrorJson", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Ip", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodenetsvc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthNodenetsvc + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthNodenetsvc + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Ip = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrefixLength", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodenetsvc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthNodenetsvc + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthNodenetsvc + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PrefixLength = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DefaultGateway", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodenetsvc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthNodenetsvc + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthNodenetsvc + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DefaultGateway = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipNodenetsvc(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthNodenetsvc + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthNodenetsvc + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ContainerNetworkInterface) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodenetsvc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ContainerNetworkInterface: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ContainerNetworkInterface: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodenetsvc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthNodenetsvc + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthNodenetsvc + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MacAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodenetsvc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthNodenetsvc + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthNodenetsvc + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MacAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NetworkNamespaceID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodenetsvc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthNodenetsvc + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthNodenetsvc + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NetworkNamespaceID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ipaddresses", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodenetsvc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthNodenetsvc + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthNodenetsvc + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Ipaddresses = append(m.Ipaddresses, &ContainerIPAddress{}) + if err := m.Ipaddresses[len(m.Ipaddresses)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipNodenetsvc(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthNodenetsvc + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthNodenetsvc + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *GetHostLocalIpAddressRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodenetsvc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GetHostLocalIpAddressRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GetHostLocalIpAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContainerID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodenetsvc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthNodenetsvc + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthNodenetsvc + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ContainerID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipNodenetsvc(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthNodenetsvc + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthNodenetsvc + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *GetHostLocalIpAddressResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodenetsvc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GetHostLocalIpAddressResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GetHostLocalIpAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IpAddr", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1453,7 +2423,7 @@ func (m *ConfigureContainerNetworkingResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.ErrorJson = string(dAtA[iNdEx:postIndex]) + m.IpAddr = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/cmd/ncproxy/nodenetsvc/nodenetsvc.proto b/cmd/ncproxy/nodenetsvc/nodenetsvc.proto index f8d2c4973f..e5f2d8eb77 100644 --- a/cmd/ncproxy/nodenetsvc/nodenetsvc.proto +++ b/cmd/ncproxy/nodenetsvc/nodenetsvc.proto @@ -6,36 +6,57 @@ service NodeNetworkService { rpc ConfigureNetworking(ConfigureNetworkingRequest) returns (ConfigureNetworkingResponse); rpc ConfigureContainerNetworking(ConfigureContainerNetworkingRequest) returns (ConfigureContainerNetworkingResponse); rpc PingNodeNetworkService(PingNodeNetworkServiceRequest) returns (PingNodeNetworkServiceResponse); + rpc GetHostLocalIpAddress(GetHostLocalIpAddressRequest) returns (GetHostLocalIpAddressResponse); } - -enum RequestType { - Setup = 0; - Teardown = 1; -} - + message ConfigureNetworkingRequest { string container_id = 1; - RequestType request_type = 2; // Setup for AddNIC and Teardown for DeleteNIC + RequestType request_type = 2; } -message ConfigureNetworkingResponse{} +message ConfigureNetworkingResponse {} message PingNodeNetworkServiceRequest { - string pingRequestMessage = 1; + string ping_request_message = 1; } message PingNodeNetworkServiceResponse { - string pingResponseMessage = 1; + string ping_response_message = 1; +} + +enum RequestType { + Setup = 0; + Teardown = 1; } -message ConfigureContainerNetworkingRequest{ +message ConfigureContainerNetworkingRequest { RequestType request_type = 1; string container_id = 2; - string network_namespace = 3; + string network_namespace_id = 3; +} + +message ConfigureContainerNetworkingResponse { + repeated ContainerNetworkInterface interfaces = 1; } -message ConfigureContainerNetworkingResponse { - bool success = 1; - string response_json = 2; - string error_json= 3; -} +message ContainerIPAddress { + string version = 1; + string ip = 3; + string prefix_length = 4; + string default_gateway = 5; +} + +message ContainerNetworkInterface { + string name = 1; + string mac_address = 2; + string network_namespace_id = 3; + repeated ContainerIPAddress ipaddresses = 4; +} + +message GetHostLocalIpAddressRequest { + string container_id = 1; +} + +message GetHostLocalIpAddressResponse { + string ip_addr = 1; +} diff --git a/internal/tools/networkagent/defs.go b/internal/tools/networkagent/defs.go new file mode 100644 index 0000000000..ddd9b6e337 --- /dev/null +++ b/internal/tools/networkagent/defs.go @@ -0,0 +1,50 @@ +package main + +import ( + "encoding/json" + "io/ioutil" + + "github.com/Microsoft/hcsshim/cmd/ncproxy/ncproxygrpc" + "github.com/pkg/errors" +) + +type service struct { + conf *config + client ncproxygrpc.NetworkConfigProxyClient + containerToNamespace map[string]string + endpointToNicID map[string]string + containerToNetwork map[string]string +} + +type hnsSettings struct { + SwitchName string `json:"switch_name,omitempty"` + IOVSettings *ncproxygrpc.IovEndpointPolicySetting `json:"iov_settings,omitempty"` +} + +type networkingSettings struct { + HNSSettings *hnsSettings `json:"hns_settings,omitempty"` +} + +type config struct { + TTRPCAddr string `json:"ttrpc,omitempty"` + GRPCAddr string `json:"grpc,omitempty"` + NodeNetSvcAddr string `json:"node_net_svc_addr,omitempty"` + // 0 represents no timeout and networkagent will continuously try and connect in the + // background. + Timeout uint32 `json:"timeout,omitempty"` + NetworkingSettings *networkingSettings `json:"networking_settings,omitempty"` +} + +// Reads config from path and returns config struct if path is valid and marshaling +// succeeds +func readConfig(path string) (*config, error) { + data, err := ioutil.ReadFile(path) + if err != nil { + return nil, errors.Wrap(err, "failed to read config file") + } + conf := &config{} + if err := json.Unmarshal(data, conf); err != nil { + return nil, errors.New("failed to unmarshal config data") + } + return conf, nil +} diff --git a/internal/tools/networkagent/main.go b/internal/tools/networkagent/main.go new file mode 100644 index 0000000000..b53a323a21 --- /dev/null +++ b/internal/tools/networkagent/main.go @@ -0,0 +1,345 @@ +package main + +import ( + "context" + "flag" + "fmt" + "math/rand" + "net" + "os" + "os/signal" + "strings" + "syscall" + + "github.com/Microsoft/go-winio/pkg/guid" + "github.com/Microsoft/hcsshim/cmd/ncproxy/ncproxygrpc" + "github.com/Microsoft/hcsshim/cmd/ncproxy/nodenetsvc" + "github.com/Microsoft/hcsshim/hcn" + "github.com/Microsoft/hcsshim/internal/log" + "github.com/sirupsen/logrus" + "google.golang.org/grpc" +) + +// This is a barebones example of an implementation of the network +// config agent service that ncproxy talks to. This is solely used to test. + +var ( + configPath = flag.String("config", "", "Path to JSON configuration file.") + + prefixLength = "24" + ipVersion = "4" +) + +func generateMAC() (string, error) { + buf := make([]byte, 6) + + _, err := rand.Read(buf) + if err != nil { + return "", err + } + + // set first number to 0 + buf[0] = 0 + mac := net.HardwareAddr(buf) + macString := strings.ToUpper(mac.String()) + macString = strings.Replace(macString, ":", "-", -1) + + return macString, nil +} + +func generateIPs(prefixLength string) (string, string, string) { + buf := []byte{192, 168, 50} + + // set last to 0 for prefix + ipPrefixBytes := append(buf, 0) + ipPrefix := net.IP(ipPrefixBytes) + ipPrefixString := ipPrefix.String() + "/" + prefixLength + + // set the last to 1 for gateway + ipGatewayBytes := append(buf, 1) + ipGateway := net.IP(ipGatewayBytes) + ipGatewayString := ipGateway.String() + + // set last byte for IP address in range + last := byte(rand.Intn(255-2) + 2) + ipBytes := append(buf, last) + ip := net.IP(ipBytes) + ipString := ip.String() + + return ipPrefixString, ipGatewayString, ipString +} + +func (s *service) ConfigureContainerNetworking(ctx context.Context, req *nodenetsvc.ConfigureContainerNetworkingRequest) (_ *nodenetsvc.ConfigureContainerNetworkingResponse, err error) { + // for testing purposes, make endpoints here + log.G(ctx).WithField("req", req).Info("ConfigureContainerNetworking request") + + if req.RequestType == nodenetsvc.RequestType_Setup { + prefixIP, gatewayIP, midIP := generateIPs(prefixLength) + + addNetworkReq := &ncproxygrpc.CreateNetworkRequest{ + Name: req.ContainerID + "_network", + Mode: ncproxygrpc.CreateNetworkRequest_Transparent, + SwitchName: s.conf.NetworkingSettings.HNSSettings.SwitchName, + IpamType: ncproxygrpc.CreateNetworkRequest_Static, + SubnetIpaddressPrefix: []string{prefixIP}, + DefaultGateway: gatewayIP, + } + + networkResp, err := s.client.CreateNetwork(ctx, addNetworkReq) + if err != nil { + return nil, err + } + + network, err := hcn.GetNetworkByID(networkResp.ID) + if err != nil { + return nil, err + } + s.containerToNetwork[req.ContainerID] = network.Name + + mac, err := generateMAC() + if err != nil { + return nil, err + } + + name := req.ContainerID + "_endpoint" + endpointCreateReq := &ncproxygrpc.CreateEndpointRequest{ + Name: name, + Macaddress: mac, + Ipaddress: midIP, + IpaddressPrefixlength: prefixLength, + NetworkName: network.Name, + IovPolicySettings: s.conf.NetworkingSettings.HNSSettings.IOVSettings, + } + + endpt, err := s.client.CreateEndpoint(ctx, endpointCreateReq) + if err != nil { + return nil, err + } + + log.G(ctx).WithField("endpt", endpt).Info("ConfigureContainerNetworking created endpoint") + + addEndpointReq := &ncproxygrpc.AddEndpointRequest{ + Name: name, + NamespaceID: req.NetworkNamespaceID, + } + _, err = s.client.AddEndpoint(ctx, addEndpointReq) + if err != nil { + return nil, err + } + s.containerToNamespace[req.ContainerID] = req.NetworkNamespaceID + + resultIPAddr := &nodenetsvc.ContainerIPAddress{ + Version: ipVersion, + Ip: midIP, + PrefixLength: prefixLength, + DefaultGateway: gatewayIP, + } + netInterface := &nodenetsvc.ContainerNetworkInterface{ + Name: network.Name, + MacAddress: mac, + NetworkNamespaceID: req.NetworkNamespaceID, + Ipaddresses: []*nodenetsvc.ContainerIPAddress{resultIPAddr}, + } + + return &nodenetsvc.ConfigureContainerNetworkingResponse{ + Interfaces: []*nodenetsvc.ContainerNetworkInterface{netInterface}, + }, nil + } else if req.RequestType == nodenetsvc.RequestType_Teardown { + eReq := &ncproxygrpc.GetEndpointsRequest{} + resp, err := s.client.GetEndpoints(ctx, eReq) + if err != nil { + return nil, err + } + + for _, endpoint := range resp.Endpoints { + if endpoint.Namespace == req.NetworkNamespaceID { + deleteEndptReq := &ncproxygrpc.DeleteEndpointRequest{ + Name: endpoint.Name, + } + if _, err := s.client.DeleteEndpoint(ctx, deleteEndptReq); err != nil { + log.G(ctx).WithField("name", endpoint.Name).Warn("failed to delete endpoint") + } + } + } + + if networkName, ok := s.containerToNetwork[req.ContainerID]; ok { + deleteReq := &ncproxygrpc.DeleteNetworkRequest{ + Name: networkName, + } + if _, err := s.client.DeleteNetwork(ctx, deleteReq); err != nil { + log.G(ctx).WithField("name", networkName).Warn("failed to delete network") + } + delete(s.containerToNetwork, req.ContainerID) + } + + return &nodenetsvc.ConfigureContainerNetworkingResponse{}, nil + + } + return nil, fmt.Errorf("invalid request type %v", req.RequestType) +} + +func (s *service) addHelper(ctx context.Context, req *nodenetsvc.ConfigureNetworkingRequest, containerNamespaceID string) (_ *nodenetsvc.ConfigureNetworkingResponse, err error) { + return s.addHNSHelper(ctx, req, containerNamespaceID) +} + +func (s *service) addHNSHelper(ctx context.Context, req *nodenetsvc.ConfigureNetworkingRequest, containerNamespaceID string) (_ *nodenetsvc.ConfigureNetworkingResponse, err error) { + eReq := &ncproxygrpc.GetEndpointsRequest{} + resp, err := s.client.GetEndpoints(ctx, eReq) + if err != nil { + return nil, err + } + log.G(ctx).WithField("endpts", resp.Endpoints).Info("ConfigureNetworking addrequest") + + for _, endpoint := range resp.Endpoints { + if endpoint.Namespace == containerNamespaceID { + // add endpoints that are in the namespace as NICs + nicID, err := guid.NewV4() + if err != nil { + return nil, fmt.Errorf("failed to create nic GUID: %s", err) + } + nsReq := &ncproxygrpc.AddNICRequest{ + ContainerID: req.ContainerID, + NicID: nicID.String(), + EndpointName: endpoint.Name, + } + if _, err := s.client.AddNIC(ctx, nsReq); err != nil { + return nil, err + } + s.endpointToNicID[endpoint.Name] = nicID.String() + } + + } + + defer func() { + if err != nil { + _, _ = s.teardownHelper(ctx, req, containerNamespaceID) + } + }() + + return &nodenetsvc.ConfigureNetworkingResponse{}, nil + +} + +func (s *service) teardownHelper(ctx context.Context, req *nodenetsvc.ConfigureNetworkingRequest, containerNamespaceID string) (*nodenetsvc.ConfigureNetworkingResponse, error) { + eReq := &ncproxygrpc.GetEndpointsRequest{} + resp, err := s.client.GetEndpoints(ctx, eReq) + if err != nil { + return nil, err + } + for _, endpoint := range resp.Endpoints { + if endpoint.Namespace == containerNamespaceID { + nicID, ok := s.endpointToNicID[endpoint.Name] + if !ok { + log.G(ctx).WithField("name", endpoint.Name).Warn("endpoint was not assigned a NIC ID previously") + continue + } + // remove endpoints that are in the namespace as NICs + nsReq := &ncproxygrpc.DeleteNICRequest{ + ContainerID: req.ContainerID, + NicID: nicID, + EndpointName: endpoint.Name, + } + if _, err := s.client.DeleteNIC(ctx, nsReq); err != nil { + log.G(ctx).WithField("name", endpoint.Name).Warn("failed to delete endpoint nic") + } + delete(s.endpointToNicID, endpoint.Name) + } + } + return &nodenetsvc.ConfigureNetworkingResponse{}, nil +} + +func (s *service) ConfigureNetworking(ctx context.Context, req *nodenetsvc.ConfigureNetworkingRequest) (*nodenetsvc.ConfigureNetworkingResponse, error) { + log.G(ctx).WithField("req", req).Info("ConfigureNetworking request") + + containerNamespaceID, ok := s.containerToNamespace[req.ContainerID] + if !ok { + return nil, fmt.Errorf("no namespace was previously created for containerID %s", req.ContainerID) + } + + if req.RequestType == nodenetsvc.RequestType_Setup { + return s.addHelper(ctx, req, containerNamespaceID) + } + return s.teardownHelper(ctx, req, containerNamespaceID) +} + +// GetHostLocalIpAddress is defined in the nodenetworksvc proto while is owned by the azure vnetagent team +//nolint:stylecheck +func (s *service) GetHostLocalIpAddress(ctx context.Context, req *nodenetsvc.GetHostLocalIpAddressRequest) (*nodenetsvc.GetHostLocalIpAddressResponse, error) { + return &nodenetsvc.GetHostLocalIpAddressResponse{IpAddr: ""}, nil +} + +func (s *service) PingNodeNetworkService(ctx context.Context, req *nodenetsvc.PingNodeNetworkServiceRequest) (*nodenetsvc.PingNodeNetworkServiceResponse, error) { + return &nodenetsvc.PingNodeNetworkServiceResponse{}, nil +} + +func main() { + var err error + ctx := context.Background() + + flag.Parse() + conf, err := readConfig(*configPath) + if err != nil { + log.G(ctx).WithError(err).Fatalf("failed to read network agent's config file at %s", *configPath) + } + log.G(ctx).WithFields(logrus.Fields{ + "config path": *configPath, + "conf": conf, + }).Info("network agent configuration") + + sigChan := make(chan os.Signal, 1) + serveErr := make(chan error, 1) + defer close(serveErr) + signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) + defer signal.Stop(sigChan) + + grpcClient, err := grpc.Dial( + conf.GRPCAddr, + grpc.WithInsecure(), + ) + if err != nil { + log.G(ctx).WithError(err).Fatalf("failed to connect to ncproxy at %s", conf.GRPCAddr) + } + defer grpcClient.Close() + + log.G(ctx).WithField("addr", conf.GRPCAddr).Info("connected to ncproxy") + ncproxyClient := ncproxygrpc.NewNetworkConfigProxyClient(grpcClient) + service := &service{ + conf: conf, + client: ncproxyClient, + containerToNamespace: make(map[string]string), + endpointToNicID: make(map[string]string), + containerToNetwork: make(map[string]string), + } + server := grpc.NewServer() + nodenetsvc.RegisterNodeNetworkServiceServer(server, service) + + grpcListener, err := net.Listen("tcp", conf.NodeNetSvcAddr) + if err != nil { + log.G(ctx).WithError(err).Fatalf("failed to listen on %s", grpcListener.Addr().String()) + } + + go func() { + defer grpcListener.Close() + if err := server.Serve(grpcListener); err != nil { + if strings.Contains(err.Error(), "use of closed network connection") { + serveErr <- nil + } + serveErr <- err + } + }() + + log.G(ctx).WithField("addr", conf.NodeNetSvcAddr).Info("serving network service agent") + + // Wait for server error or user cancellation. + select { + case <-sigChan: + log.G(ctx).Info("Received interrupt. Closing") + case err := <-serveErr: + if err != nil { + log.G(ctx).WithError(err).Fatal("grpc service failure") + } + } + + // Cancel inflight requests and shutdown service + server.GracefulStop() +} diff --git a/test/vendor/github.com/Microsoft/hcsshim/.golangci.yml b/test/vendor/github.com/Microsoft/hcsshim/.golangci.yml index 16b25be554..728178cff4 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/.golangci.yml +++ b/test/vendor/github.com/Microsoft/hcsshim/.golangci.yml @@ -24,6 +24,16 @@ issues: linters: - stylecheck Text: "ST1003:" + + - path: cmd\\ncproxy\\nodenetsvc\\ + linters: + - stylecheck + Text: "ST1003:" + + - path: cmd\\ncproxy_mock\\ + linters: + - stylecheck + Text: "ST1003:" - path: internal\\hcs\\schema2\\ linters: