aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/tcp/tcp_packet.h
blob: 9ccfe6553ff9ad97ae4ff6600f40fbb7eb6c9eda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
 * Copyright (c) 2016 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef included_tcp_packet_h
#define included_tcp_packet_h

#include <vnet/vnet.h>

/* TCP flags bit 0 first. */
#define foreach_tcp_flag                                \
  _ (FIN) /**< No more data from sender. */             \
  _ (SYN) /**< Synchronize sequence numbers. */         \
  _ (RST) /**< Reset the connection. */                 \
  _ (PSH) /**< Push function. */                        \
  _ (ACK) /**< Ack field significant. */                \
  _ (URG) /**< Urgent pointer field significant. */     \
  _ (ECE) /**< ECN-echo. Receiver got CE packet */      \
  _ (CWR) /**< Sender reduced congestion window */

enum
{
#define _(f) TCP_FLAG_BIT_##f,
  foreach_tcp_flag
#undef _
    TCP_N_FLAG_BITS,
};

enum
{
#define _(f) TCP_FLAG_##f = 1 << TCP_FLAG_BIT_##f,
  foreach_tcp_flag
#undef _
};

typedef struct _tcp_header
{
  union
  {
    struct
    {
      u16 src_port; /**< Source port. */
      u16 dst_port; /**< Destination port. */
    };
    struct
    {
      u16 src, dst;
    };
  };

  u32 seq_number;	/**< Sequence number of the first data octet in this
                         *   segment, except when SYN is present. If SYN
                         *   is present the seq number is is the ISN and the
                         *   first data octet is ISN+1 */
  u32 ack_number;	/**< Acknowledgement number if ACK is set. It contains
                         *   the value of the next sequence number the sender
                         *   of the segment is expecting to receive. */
  u8 data_offset_and_reserved;
  u8 flags;		/**< Flags: see the macro above */
  u16 window;		/**< Number of bytes sender is willing to receive. */

  u16 checksum;		/**< Checksum of TCP pseudo header and data. */
  u16 urgent_pointer;	/**< Seq number of the byte after the urgent data. */
} __attribute__ ((packed)) tcp_header_t;

/* Flag tests that return 0 or !0 */
#define tcp_doff(_th) ((_th)->data_offset_and_reserved >> 4)
#define tcp_fin(_th) ((_th)->flags & TCP_FLAG_FIN)
#define tcp_syn(_th) ((_th)->flags & TCP_FLAG_SYN)
#define tcp_rst(_th) ((_th)->flags & TCP_FLAG_RST)
#define tcp_psh(_th) ((_th)->flags & TCP_FLAG_PSH)
#define tcp_ack(_th) ((_th)->flags & TCP_FLAG_ACK)
#define tcp_urg(_th) ((_th)->flags & TCP_FLAG_URG)
#define tcp_ece(_th) ((_th)->flags & TCP_FLAG_ECE)
#define tcp_cwr(_th) ((_th)->flags & TCP_FLAG_CWR)

/* Flag tests that return 0 or 1 */
#define tcp_is_syn(_th) !!((_th)->flags & TCP_FLAG_SYN)
#define tcp_is_fin(_th) !!((_th)->flags & TCP_FLAG_FIN)

always_inline int
tcp_header_bytes (tcp_header_t * t)
{
  return tcp_doff (t) * sizeof (u32);
}

/*
 * TCP options.
 */

typedef enum tcp_option_type
{
  TCP_OPTION_EOL = 0,			/**< End of options. */
  TCP_OPTION_NOOP = 1,			/**< No operation. */
  TCP_OPTION_MSS = 2,			/**< Limit MSS. */
  TCP_OPTION_WINDOW_SCALE = 3,		/**< Window scale. */
  TCP_OPTION_SACK_PERMITTED = 4,	/**< Selective Ack permitted. */
  TCP_OPTION_SACK_BLOCK = 5,		/**< Selective Ack block. */
  TCP_OPTION_TIMESTAMP = 8,		/**< Timestamps. */
  TCP_OPTION_UTO = 28,			/**< User timeout. */
  TCP_OPTION_AO = 29,			/**< Authentication Option. */
} tcp_option_type_t;

#define foreach_tcp_options_flag                                        \
  _ (MSS)               /**< MSS advertised in SYN */                   \
  _ (TSTAMP)            /**< Timestamp capability advertised in SYN */  \
  _ (WSCALE)            /**< Wnd scale capability advertised in SYN */  \
  _ (SACK_PERMITTED)    /**< SACK capability advertised in SYN */       \
  _ (SACK)		/**< SACK present */

enum
{
#define _(f) TCP_OPTS_FLAG_BIT_##f,
  foreach_tcp_options_flag
#undef _
    TCP_OPTIONS_N_FLAG_BITS,
};

enum
{
#define _(f) TCP_OPTS_FLAG_##f = 1 << TCP_OPTS_FLAG_BIT_##f,
  foreach_tcp_options_flag
#undef _
};

typedef struct _sack_block
{
  u32 start;		/**< Start sequence number */
  u32 end;		/**< End sequence number (first outside) */
} sack_block_t;

typedef struct
{
  u8 flags;		/** Option flags, see above */

  u16 mss;		/**< Maximum segment size advertised */
  u8 wscale;		/**< Window scale advertised */
  u32 tsval;		/**< Timestamp value */
  u32 tsecr;		/**< Echoed/reflected time stamp */
  sack_block_t *sacks;	/**< SACK blocks */
  u8 n_sack_blocks;	/**< Number of SACKs blocks */
} tcp_options_t;

/* Flag tests that return 0 or !0 */
#define tcp_opts_mss(_to) ((_to)->flags & TCP_OPTS_FLAG_MSS)
#define tcp_opts_tstamp(_to) ((_to)->flags & TCP_OPTS_FLAG_TSTAMP)
#define tcp_opts_wscale(_to) ((_to)->flags & TCP_OPTS_FLAG_WSCALE)
#define tcp_opts_sack(_to) ((_to)->flags & TCP_OPTS_FLAG_SACK)
#define tcp_opts_sack_permitted(_to) ((_to)->flags & TCP_OPTS_FLAG_SACK_PERMITTED)

/* TCP option lengths */
#define TCP_OPTION_LEN_EOL              1
#define TCP_OPTION_LEN_NOOP             1
#define TCP_OPTION_LEN_MSS              4
#define TCP_OPTION_LEN_WINDOW_SCALE     3
#define TCP_OPTION_LEN_SACK_PERMITTED   2
#define TCP_OPTION_LEN_TIMESTAMP        10
#define TCP_OPTION_LEN_SACK_BLOCK        8

#define TCP_HDR_LEN_MAX			60
#define TCP_WND_MAX                     65535U
#define TCP_MAX_WND_SCALE               14	/* See RFC 1323 */
#define TCP_OPTS_ALIGN                  4
#define TCP_OPTS_MAX_SACK_BLOCKS        3
#endif /* included_tcp_packet_h */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
length; miss_packet_type_t type; } miss_packet_t; typedef struct { u8 mac[6]; u32 ip4; } lisp_api_l2_arp_entry_t; typedef struct { u8 mac[6]; u8 ip6[16]; } lisp_api_ndp_entry_t; typedef enum { MR_MODE_DST_ONLY = 0, MR_MODE_SRC_DST, _MR_MODE_MAX } map_request_mode_t; #define foreach_lisp_flag_bit \ _(USE_PETR, "Use Proxy-ETR") \ _(XTR_MODE, "ITR/ETR mode") \ _(PETR_MODE, "Use Proxy-ETR") \ _(PITR_MODE, "Proxy-ITR mode") \ _(STATS_ENABLED, "Statistics enabled") typedef enum lisp_flag_bits { #define _(sym, str) LISP_FLAG_BIT_##sym, foreach_lisp_flag_bit #undef _ } lisp_flag_bits_e; typedef enum lisp_flags { #define _(sym, str) LISP_FLAG_##sym = 1 << LISP_FLAG_BIT_##sym, foreach_lisp_flag_bit #undef _ } lisp_flags_e; typedef struct { ip_address_t addr; u32 bd; } lisp_l2_arp_key_t; typedef enum { LISP_TRANSPORT_PROTOCOL_UDP = 1, LISP_TRANSPORT_PROTOCOL_API } lisp_transport_protocol_t; typedef struct { u64 nonce; u8 is_rloc_probe; mapping_t *mappings; volatile u8 is_free; } map_records_arg_t; typedef struct { u32 flags; /* LISP feature status */ u8 is_enabled; /* eid table */ gid_dictionary_t mapping_index_by_gid; /* pool of mappings */ mapping_t *mapping_pool; /* hash map of secret keys by mapping index */ u8 *key_by_mapping_index; /* pool of locators */ locator_t *locator_pool; /* pool of locator-sets */ locator_set_t *locator_set_pool; /* vector of locator-set vectors composed of and indexed by locator index */ u32 **locator_to_locator_sets; /* hash map of locators by name */ uword *locator_set_index_by_name; /* vector of eid index vectors supported and indexed by locator-set index */ u32 **locator_set_to_eids; /* vectors of indexes for local locator-sets and mappings */ u32 *local_mappings_indexes; u32 *local_locator_set_indexes; /* hash map of forwarding entries by mapping index */ u32 *fwd_entry_by_mapping_index; /* pool of vectors of rmts per lcl mapping in adjacencies */ u32 **lcl_to_rmt_adjacencies; /* hash of pool positions of vectors of rmts by lcl mapping index */ u32 *lcl_to_rmt_adjs_by_lcl_idx; /* forwarding entries pool */ fwd_entry_t *fwd_entry_pool; /* hash map keyed by nonce of pending map-requests */ uword *pending_map_requests_by_nonce; /* pool of pending map requests */ pending_map_request_t *pending_map_requests_pool; /* pool of pending map registers */ pending_map_register_t *pending_map_registers_pool; /* hash map of sent map register messages */ uword *map_register_messages_by_nonce; /* vector of map-resolvers */ lisp_msmr_t *map_resolvers; /* vector of map-servers */ lisp_msmr_t *map_servers; /* map resolver address currently being used for sending requests. * This has to be an actual address and not an index to map_resolvers vector * since the vector may be modified during request resend/retry procedure * and break things :-) */ ip_address_t active_map_resolver; ip_address_t active_map_server; u8 do_map_resolver_election; u8 do_map_server_election; /* map-request locator set index */ u32 mreq_itr_rlocs; /* vni to vrf hash tables */ uword *table_id_by_vni; uword *vni_by_table_id; /* vni to bd-index hash tables */ uword *bd_id_by_vni; uword *vni_by_bd_id; /* track l2 and l3 interfaces that have been created for vni */ uword *l2_dp_intf_by_vni; /* Proxy ITR map index */ u32 pitr_map_index; /** Proxy ETR map index used for 'use-petr'. * Not related to PETR tunnel mode */ u32 petr_map_index; /* mapping index for NSH */ u32 nsh_map_index; /* map request mode */ u8 map_request_mode; /* enable/disable map registering */ u8 map_registering; /* enable/disable rloc-probing */ u8 rloc_probing; /* timing wheel for mappping timeouts */ timing_wheel_t wheel; /** Per thread pool of records shared with thread0 */ map_records_arg_t **map_records_args_pool; /* TTL used for all mappings when registering */ u32 map_register_ttl; /* control variables for map server election */ u32 max_expired_map_registers; u32 expired_map_registers; /** either UDP based or binary API. Default is UDP */ lisp_transport_protocol_t transport_protocol; /* commodity */ ip4_main_t *im4; ip6_main_t *im6; vlib_main_t *vlib_main; vnet_main_t *vnet_main; } lisp_cp_main_t; /* lisp-gpe control plane */ extern lisp_cp_main_t lisp_control_main; extern vlib_node_registration_t lisp_cp_input_node; extern vlib_node_registration_t lisp_cp_lookup_ip4_node; extern vlib_node_registration_t lisp_cp_lookup_ip6_node; clib_error_t *lisp_cp_init (); always_inline lisp_cp_main_t * vnet_lisp_cp_get_main () { return &lisp_control_main; } void get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b, gid_address_t * src, gid_address_t * dst, u16 type); typedef struct { u8 is_add; union { u8 *name; u32 index; }; locator_t *locators; u8 local; } vnet_lisp_add_del_locator_set_args_t; int vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a, u32 * ls_index); int vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a, locator_set_t * ls, u32 * ls_index); typedef struct { u8 is_add; gid_address_t eid; u32 locator_set_index; u32 ttl; u8 action; u8 authoritative; u8 local; u8 is_static; u8 *key; u8 key_id; } vnet_lisp_add_del_mapping_args_t; int vnet_lisp_map_cache_add_del (vnet_lisp_add_del_mapping_args_t * a, u32 * map_index); int vnet_lisp_add_del_local_mapping (vnet_lisp_add_del_mapping_args_t * a, u32 * map_index_result); int vnet_lisp_add_mapping (vnet_lisp_add_del_mapping_args_t * a, locator_t * rlocs, u32 * res_map_index, u8 * is_changed); int vnet_lisp_del_mapping (gid_address_t * eid, u32 * res_map_index); typedef struct { gid_address_t reid; gid_address_t leid; u8 is_add; } vnet_lisp_add_del_adjacency_args_t; int vnet_lisp_add_del_adjacency (vnet_lisp_add_del_adjacency_args_t * a); typedef struct { u8 is_add; ip_address_t address; } vnet_lisp_add_del_map_resolver_args_t; int vnet_lisp_add_del_map_resolver (vnet_lisp_add_del_map_resolver_args_t * a); int vnet_lisp_add_del_map_server (ip_address_t * addr, u8 is_add); clib_error_t *vnet_lisp_enable_disable (u8 is_enabled); u8 vnet_lisp_enable_disable_status (void); int vnet_lisp_pitr_set_locator_set (u8 * locator_set_name, u8 is_add); int vnet_lisp_use_petr (ip_address_t * ip, u8 is_add); typedef struct { u8 is_add; u8 *locator_set_name; } vnet_lisp_add_del_mreq_itr_rloc_args_t; int vnet_lisp_add_del_mreq_itr_rlocs (vnet_lisp_add_del_mreq_itr_rloc_args_t * a); int vnet_lisp_clear_all_remote_adjacencies (void); int vnet_lisp_eid_table_map (u32 vni, u32 vrf, u8 is_l2, u8 is_add); int vnet_lisp_add_del_map_table_key (gid_address_t * eid, char *key, u8 is_add); int vnet_lisp_set_map_request_mode (u8 mode); u8 vnet_lisp_get_map_request_mode (void); lisp_adjacency_t *vnet_lisp_adjacencies_get_by_vni (u32 vni); int vnet_lisp_rloc_probe_enable_disable (u8 is_enable); int vnet_lisp_map_register_enable_disable (u8 is_enable); u8 vnet_lisp_map_register_state_get (void); u8 vnet_lisp_rloc_probe_state_get (void); int vnet_lisp_add_del_l2_arp_ndp_entry (gid_address_t * key, u8 * mac, u8 is_add); u32 *vnet_lisp_l2_arp_bds_get (void); lisp_api_l2_arp_entry_t *vnet_lisp_l2_arp_entries_get_by_bd (u32 bd); int vnet_lisp_nsh_set_locator_set (u8 * locator_set_name, u8 is_add); int vnet_lisp_map_register_set_ttl (u32 ttl); u32 vnet_lisp_map_register_get_ttl (void); int vnet_lisp_map_register_fallback_threshold_set (u32 value); u32 vnet_lisp_map_register_fallback_threshold_get (void); u32 *vnet_lisp_ndp_bds_get (void); lisp_api_ndp_entry_t *vnet_lisp_ndp_entries_get_by_bd (u32 bd); u32 vnet_lisp_set_transport_protocol (u8 protocol); lisp_transport_protocol_t vnet_lisp_get_transport_protocol (void); extern int vnet_lisp_enable_disable_xtr_mode (u8 is_enabled); extern int vnet_lisp_enable_disable_pitr_mode (u8 is_enabled); extern int vnet_lisp_enable_disable_petr_mode (u8 is_enabled); extern u8 vnet_lisp_get_xtr_mode (void); extern u8 vnet_lisp_get_pitr_mode (void); extern u8 vnet_lisp_get_petr_mode (void); map_records_arg_t *parse_map_reply (vlib_buffer_t * b); always_inline mapping_t * lisp_get_petr_mapping (lisp_cp_main_t * lcm) { return pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); } #endif /* VNET_CONTROL_H_ */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */