datapath: Avoid possibility of negative 'n_ports' in struct odp_portvec.
[sliver-openvswitch.git] / include / openvswitch / datapath-protocol.h
index 2ae0c82..0e8d5c9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009 Nicira Networks.
+ * Copyright (c) 2009, 2010 Nicira Networks.
  *
  * This file is offered under your choice of two licenses: Apache 2.0 or GNU
  * GPL 2.0 or later.  The permission statements for each of these licenses is
@@ -61,8 +61,8 @@
 #define ODP_GET_LISTEN_MASK     _IOW('O', 5, int)
 #define ODP_SET_LISTEN_MASK     _IOR('O', 6, int)
 
-#define ODP_PORT_ADD            _IOR('O', 7, struct odp_port)
-#define ODP_PORT_DEL            _IOR('O', 8, int)
+#define ODP_PORT_ATTACH         _IOR('O', 7, struct odp_port)
+#define ODP_PORT_DETACH         _IOR('O', 8, int)
 #define ODP_PORT_QUERY          _IOWR('O', 9, struct odp_port)
 #define ODP_PORT_LIST           _IOWR('O', 10, struct odp_portvec)
 
 
 #define ODP_EXECUTE             _IOR('O', 18, struct odp_execute)
 
-#define ODP_SET_SFLOW_PROBABILITY _IOR('O', 20, int)
-#define ODP_GET_SFLOW_PROBABILITY _IOW('O', 21, int)
+#define ODP_SET_SFLOW_PROBABILITY _IOR('O', 19, int)
+#define ODP_GET_SFLOW_PROBABILITY _IOW('O', 20, int)
+
+#define ODP_VPORT_ADD           _IOR('O', 21, struct odp_vport_add)
+#define ODP_VPORT_MOD           _IOR('O', 22, struct odp_vport_mod)
+#define ODP_VPORT_DEL           _IO('O', 23)
+#define ODP_VPORT_STATS_GET     _IOWR('O', 24, struct odp_vport_stats_req)
+#define ODP_VPORT_ETHER_GET     _IOWR('O', 25, struct odp_vport_ether)
+#define ODP_VPORT_ETHER_SET     _IOW('O', 26, struct odp_vport_ether)
+#define ODP_VPORT_MTU_GET       _IOWR('O', 27, struct odp_vport_mtu)
+#define ODP_VPORT_MTU_SET       _IOW('O', 28, struct odp_vport_mtu)
 
 struct odp_stats {
     /* Flows. */
@@ -107,6 +116,7 @@ struct odp_stats {
 /* Logical ports. */
 #define ODPP_LOCAL      ((__u16)0)
 #define ODPP_NONE       ((__u16)-1)
+#define ODPP_NORMAL     ((__u16)-2)
 
 /* Listening channels. */
 #define _ODPL_MISS_NR   0       /* Packet missed in flow table. */
@@ -117,30 +127,48 @@ struct odp_stats {
 #define ODPL_SFLOW      (1 << _ODPL_SFLOW_NR)
 #define ODPL_ALL        (ODPL_MISS | ODPL_ACTION | ODPL_SFLOW)
 
-/* Format of messages read from datapath fd. */
+/**
+ * struct odp_msg - format of messages read from datapath fd.
+ * @type: One of the %_ODPL_* constants.
+ * @length: Total length of message, including this header.
+ * @port: Port that received the packet embedded in this message.
+ * @reserved: Not currently used.  Should be set to 0.
+ * @arg: Argument value whose meaning depends on @type.
+ *
+ * For @type == %_ODPL_MISS_NR, the header is followed by packet data.  The
+ * @arg member is the ID (in network byte order) of the tunnel that
+ * encapsulated this packet. It is 0 if the packet was not received on a tunnel.
+ *
+ * For @type == %_ODPL_ACTION_NR, the header is followed by packet data.  The
+ * @arg member is copied from the &struct odp_action_controller that caused
+ * the &struct odp_msg to be composed.
+ *
+ * For @type == %_ODPL_SFLOW_NR, the header is followed by &struct
+ * odp_sflow_sample_header, then by an array of &union odp_action (the number
+ * of which is specified in &struct odp_sflow_sample_header), then by packet
+ * data.
+ */
 struct odp_msg {
-    __u32 type;                 /* _ODPL_MISS_NR or _ODPL_ACTION_NR. */
-    __u32 length;               /* Message length, including header. */
-    __u16 port;                 /* Port on which frame was received. */
+    __u32 type;
+    __u32 length;
+    __u16 port;
     __u16 reserved;
-    __u32 arg;                  /* Argument value specified in action. */
-
-    /*
-     * Followed by:
-     *
-     * ODPL_MISS, ODPL_ACTION: packet data.
-     *
-     * ODPL_SFLOW: "struct odp_sflow_sample_header", followed by
-     *   an array of "union odp_action"s, followed by packet data.
-     */
+    __u32 arg;
 };
 
-/* Header added to sFlow sampled packet. */
+/**
+ * struct odp_sflow_sample_header - header added to sFlow sampled packet.
+ * @sample_pool: Number of packets that were candidates for sFlow sampling,
+ * regardless of whether they were actually chosen and sent down to userspace.
+ * @n_actions: Number of "union odp_action"s immediately following this header.
+ *
+ * This header follows &struct odp_msg when that structure's @type is
+ * %_ODPL_SFLOW_NR, and it is itself followed by an array of &union odp_action
+ * (the number of which is specified in @n_actions) and then by packet data.
+ */
 struct odp_sflow_sample_header {
-    __u64 sample_pool;          /* Number of potentially sampled packets. */
-    __u32 n_actions;            /* Number of following "union odp_action"s. */
-    __u32 reserved;             /* Pad up to 64-bit boundary. */
-    /* Followed by n_action "union odp_action"s. */
+    __u32 sample_pool;
+    __u32 n_actions;
 };
 
 #define ODP_PORT_INTERNAL (1 << 0) /* This port is simulated. */
@@ -153,7 +181,7 @@ struct odp_port {
 
 struct odp_portvec {
     struct odp_port *ports;
-    int n_ports;
+    __u32 n_ports;
 };
 
 struct odp_port_group {
@@ -173,6 +201,7 @@ struct odp_flow_stats {
 };
 
 struct odp_flow_key {
+    __be32 tun_id;               /* Encapsulating tunnel ID. */
     __be32 nw_src;               /* IP source address. */
     __be32 nw_dst;               /* IP destination address. */
     __u16  in_port;              /* Input switch port. */
@@ -184,7 +213,9 @@ struct odp_flow_key {
     __u8   dl_dst[ETH_ALEN];     /* Ethernet destination address. */
     __u8   nw_proto;             /* IP protocol or lower 8 bits of 
                                     ARP opcode. */
-    __u8   reserved;             /* Pad to 64 bits. */
+    __u8   dl_vlan_pcp;          /* Input VLAN priority. */
+    __u8   nw_tos;               /* IP ToS (DSCP field, 6 bits). */
+    __u8   reserved[3];          /* Align to 32-bits...must be zeroed. */
 };
 
 /* Flags for ODP_FLOW. */
@@ -211,7 +242,7 @@ struct odp_flow_put {
 
 struct odp_flowvec {
     struct odp_flow *flows;
-    int n_flows;
+    __u32 n_flows;
 };
 
 /* The VLAN id is 12 bits, so we can use the entire 16 bits to indicate
@@ -230,9 +261,11 @@ struct odp_flowvec {
 #define ODPAT_SET_DL_DST        7    /* Ethernet destination address. */
 #define ODPAT_SET_NW_SRC        8    /* IP source address. */
 #define ODPAT_SET_NW_DST        9    /* IP destination address. */
-#define ODPAT_SET_TP_SRC        10   /* TCP/UDP source port. */
-#define ODPAT_SET_TP_DST        11   /* TCP/UDP destination port. */
-#define ODPAT_N_ACTIONS         12
+#define ODPAT_SET_NW_TOS        10   /* IP ToS/DSCP field (6 bits). */
+#define ODPAT_SET_TP_SRC        11   /* TCP/UDP source port. */
+#define ODPAT_SET_TP_DST        12   /* TCP/UDP destination port. */
+#define ODPAT_SET_TUNNEL        13   /* Set the encapsulating tunnel ID. */
+#define ODPAT_N_ACTIONS         14
 
 struct odp_action_output {
     __u16 type;                  /* ODPAT_OUTPUT. */
@@ -254,6 +287,12 @@ struct odp_action_controller {
     __u32 arg;                  /* Copied to struct odp_msg 'arg' member. */
 };
 
+struct odp_action_tunnel {
+    __u16 type;                 /* ODPAT_SET_TUNNEL. */
+    __u16 reserved;
+    __be32 tun_id;              /* Tunnel ID. */
+};
+
 /* Action structure for ODPAT_SET_VLAN_VID. */
 struct odp_action_vlan_vid {
     __u16 type;                  /* ODPAT_SET_VLAN_VID. */
@@ -284,6 +323,14 @@ struct odp_action_nw_addr {
     __be32 nw_addr;             /* IP address. */
 };
 
+struct odp_action_nw_tos {
+    __u16 type;                  /* ODPAT_SET_NW_TOS. */
+    __u8 nw_tos;                 /* IP ToS/DSCP field (6 bits). */
+    __u8 reserved1;
+    __u16 reserved2;
+    __u16 reserved3;
+};
+
 /* Action structure for ODPAT_SET_TP_SRC/DST. */
 struct odp_action_tp_port {
     __u16 type;                  /* ODPAT_SET_TP_SRC/DST. */
@@ -297,10 +344,12 @@ union odp_action {
     struct odp_action_output output;
     struct odp_action_output_group output_group;
     struct odp_action_controller controller;
+    struct odp_action_tunnel tunnel;
     struct odp_action_vlan_vid vlan_vid;
     struct odp_action_vlan_pcp vlan_pcp;
     struct odp_action_dl_addr dl_addr;
     struct odp_action_nw_addr nw_addr;
+    struct odp_action_nw_tos nw_tos;
     struct odp_action_tp_port tp_port;
 };
 
@@ -316,6 +365,48 @@ struct odp_execute {
     __u32 length;
 };
 
+#define VPORT_TYPE_SIZE     16
+struct odp_vport_add {
+    char port_type[VPORT_TYPE_SIZE];
+    char devname[16];            /* IFNAMSIZ */
+    void *config;
+};
+
+struct odp_vport_mod {
+    char devname[16];            /* IFNAMSIZ */
+    void *config;
+};
+
+struct odp_vport_stats {
+    __u64 rx_packets;
+    __u64 tx_packets;
+    __u64 rx_bytes;
+    __u64 tx_bytes;
+    __u64 rx_dropped;
+    __u64 tx_dropped;
+    __u64 rx_errors;
+    __u64 tx_errors;
+    __u64 rx_frame_err;
+    __u64 rx_over_err;
+    __u64 rx_crc_err;
+    __u64 collisions;
+};
+
+struct odp_vport_stats_req {
+    char devname[16];            /* IFNAMSIZ */
+    struct odp_vport_stats stats;
+};
+
+struct odp_vport_ether {
+    char devname[16];            /* IFNAMSIZ */
+    unsigned char ether_addr[ETH_ALEN];
+};
+
+struct odp_vport_mtu {
+    char devname[16];            /* IFNAMSIZ */
+    __u16 mtu;
+};
+
 /* Values below this cutoff are 802.3 packets and the two bytes
  * following MAC addresses are used as a frame length.  Otherwise, the
  * two bytes are used as the Ethernet type.