syntax = "proto3";

package network;

option go_package = "github.com/talos-systems/talos/pkg/machinery/api/network";

import "google/protobuf/empty.proto";
import "common/common.proto";

// The network service definition.
service NetworkService {
  rpc Routes(google.protobuf.Empty) returns (RoutesResponse) {
    option deprecated = true;
  };
  rpc Interfaces(google.protobuf.Empty) returns (InterfacesResponse) {
    option deprecated = true;
  };
}

enum AddressFamily {
  option allow_alias = true;
  AF_UNSPEC = 0;
  AF_INET = 2;
  IPV4 = 2;
  AF_INET6 = 10;
  IPV6 = 10;
}

enum RouteProtocol {
  RTPROT_UNSPEC = 0;
  RTPROT_REDIRECT = 1; // Route installed by ICMP redirects
  RTPROT_KERNEL = 2; // Route installed by kernel
  RTPROT_BOOT = 3; // Route installed during boot
  RTPROT_STATIC = 4; // Route installed by administrator
  RTPROT_GATED = 8; // Route installed by gated
  RTPROT_RA = 9; // Route installed by router advertisement
  RTPROT_MRT = 10; // Route installed by Merit MRT
  RTPROT_ZEBRA = 11; // Route installed by Zebra/Quagga
  RTPROT_BIRD = 12; // Route installed by Bird
  RTPROT_DNROUTED = 13; // Route installed by DECnet routing daemon
  RTPROT_XORP = 14; // Route installed by XORP
  RTPROT_NTK = 15; // Route installed by Netsukuku
  RTPROT_DHCP = 16; // Route installed by DHCP
  RTPROT_MROUTED = 17; // Route installed by Multicast daemon
  RTPROT_BABEL = 42; // Route installed by Babel daemon
}

enum InterfaceFlags {
  FLAG_UNKNOWN = 0;
  FLAG_UP = 1;
  FLAG_BROADCAST = 2;
  FLAG_LOOPBACK = 3;
  FLAG_POINT_TO_POINT = 4;
  FLAG_MULTICAST = 5;
}

// The messages message containing the routes.
message RoutesResponse {
  repeated Routes messages = 1;
}

message Routes {
  common.Metadata metadata = 1;
  repeated Route routes = 2;
}

// The messages message containing a route.
message Route {
  // Interface is the interface over which traffic to this destination should be sent
  string interface = 1;
  // Destination is the network prefix CIDR which this route provides
  string destination = 2;
  // Gateway is the gateway address to which traffic to this destination should be sent
  string gateway = 3;
  // Metric is the priority of the route, where lower metrics have higher priorities
  uint32 metric = 4;
  // Scope desribes the scope of this route
  uint32 scope = 5;
  // Source is the source prefix CIDR for the route, if one is defined
  string source = 6;
  // Family is the address family of the route.  Currently, the only options are AF_INET (IPV4) and AF_INET6 (IPV6).
  AddressFamily family = 7;
  // Protocol is the protocol by which this route came to be in place
  RouteProtocol protocol = 8;
  // Flags indicate any special flags on the route
  uint32 flags = 9;
}

message InterfacesResponse {
  repeated Interfaces messages = 1;
}

message Interfaces {
	common.Metadata metadata = 1;
  repeated Interface interfaces = 2;
}

// Interface represents a net.Interface
message Interface {
  uint32 index = 1;
  uint32 mtu = 2;
  string name = 3;
  string hardwareaddr = 4;
  InterfaceFlags flags = 5;
  repeated string ipaddress = 6;
}
