36 }) ike_notify_payload_header_t;
59 }) ike_ts_payload_header_t;
83 }) ike_sa_transform_data_t;
98 static ike_payload_header_t *
101 ike_payload_header_t *hdr =
106 hdr->nextpayload = payload_type;
112 hdr = (ike_payload_header_t *) tmp;
115 hdr->length = clib_host_to_net_u16 (len);
124 ike_payload_header_t *hdr;
128 len = clib_net_to_host_u16 (hdr->length);
129 hdr->length = clib_host_to_net_u16 (len +
vec_len (data));
142 ike_notify_payload_header_t *n;
148 n->msg_type = clib_host_to_net_u16 (msg_type);
164 ike_payload_header_t *ph;
166 ike_sa_transform_data_t *tr;
181 prop->last_or_more = proposals - p + 1 <
vec_len (proposals) ? 2 : 0;
184 prop->spi_size = spi_size;
188 prop->spi[0] = clib_host_to_net_u32 (p->
spi);
190 DBG_PLD (
"proposal num %u protocol_id %u last_or_more %u spi_size %u%s%U",
191 prop->proposal_num, prop->protocol_id, prop->last_or_more,
192 prop->spi_size, prop->spi_size ?
" spi_data " :
"",
198 tr = (ike_sa_transform_data_t *) tmp;
201 tr->transform_type = t->
type;
202 tr->transform_id = clib_host_to_net_u16 (t->
transform_id);
204 clib_host_to_net_u16 (
sizeof (*tr) +
vec_len (t->
attrs));
210 (
"transform type %U transform_id %u last_or_more %u attr_size %u%s%U",
229 ike_ke_payload_header_t *ke;
233 ke->dh_group = clib_host_to_net_u16 (dh_group);
241 sizeof (ike_payload_header_t));
248 ike_id_payload_header_t *idp;
253 idp->id_type =
id->type;
276 dp->num_of_spi = clib_host_to_net_u16 (num_of_spi);
280 u32 spi = clib_host_to_net_u32 (d2->
spi);
291 ike_auth_payload_header_t *ap;
297 ap->auth_method = auth->
method;
304 ike_ts_payload_header_t *tsh;
317 vec_add2 (data, tmp,
sizeof (*entry));
321 entry->selector_len = clib_host_to_net_u16 (16);
322 entry->start_port = clib_host_to_net_u16 (ts2->
start_port);
323 entry->end_port = clib_host_to_net_u16 (ts2->
end_port);
335 u8 *tmp __attribute__ ((unused));
348 u32 plen = clib_net_to_host_u16 (ikep->length);
351 int proposal_ptr = 0;
359 DBG_PLD (
"proposal num %u len %u last_or_more %u id %u " 360 "spi_size %u num_transforms %u",
361 sap->proposal_num, clib_net_to_host_u16 (sap->proposal_len),
362 sap->last_or_more, sap->protocol_id, sap->spi_size,
363 sap->num_transforms);
373 transform_ptr = proposal_ptr +
sizeof (*sap) + sap->spi_size;
379 if (sap->spi_size == 4)
381 proposal->
spi = clib_net_to_host_u32 (sap->spi[0]);
384 for (
i = 0;
i < sap->num_transforms;
i++)
386 ike_sa_transform_data_t *tr =
387 (ike_sa_transform_data_t *) & ikep->payload[transform_ptr];
388 u16 tlen = clib_net_to_host_u16 (tr->transform_len);
390 if (tlen <
sizeof (*tr))
395 transform->
type = tr->transform_type;
396 transform->
transform_id = clib_net_to_host_u16 (tr->transform_id);
397 if (tlen >
sizeof (*tr))
398 vec_add (transform->
attrs, tr->attributes, tlen - sizeof (*tr));
401 (
"transform num %u len %u last_or_more %u type %U id %u%s%U",
i,
403 clib_net_to_host_u16 (tr->transform_id),
405 tr->attributes, tlen - sizeof (*tr));
407 transform_ptr += tlen;
410 proposal_ptr += clib_net_to_host_u16 (sap->proposal_len);
412 while (proposal_ptr < (plen -
sizeof (*ikep)) && sap->last_or_more == 2);
415 if (proposal_ptr != (plen -
sizeof (*ikep)) || sap->last_or_more)
421 DBG_PLD (
"SA payload data corrupted");
429 ike_ts_payload_header_t *tsp = (ike_ts_payload_header_t *) ikep;
433 for (i = 0; i < tsp->num_ts; i++)
435 if (tsp->ts[i].ts_type != 7)
437 DBG_PLD (
"unsupported TS type received (%u)", tsp->ts[i].ts_type);
442 ts->ts_type = tsp->ts[
i].ts_type;
443 ts->protocol_id = tsp->ts[
i].protocol_id;
444 ts->start_port = tsp->ts[
i].start_port;
445 ts->end_port = tsp->ts[
i].end_port;
446 ts->start_addr.as_u32 = tsp->ts[
i].start_addr.as_u32;
447 ts->end_addr.as_u32 = tsp->ts[
i].end_addr.as_u32;
455 ike_notify_payload_header_t *n = (ike_notify_payload_header_t *) ikep;
456 u32 plen = clib_net_to_host_u16 (ikep->length);
460 DBG_PLD (
"msg_type %U len %u%s%U",
462 plen, plen > sizeof (*n) ?
" data " :
"",
466 r->
msg_type = clib_net_to_host_u16 (n->msg_type);
469 if (n->spi_size == 4)
472 r->
spi = clib_net_to_host_u32 (spi);
475 else if (n->spi_size == 0)
484 if (plen > (
sizeof (*n) + n->spi_size))
487 plen - sizeof (*n) - n->spi_size);
496 u32 plen = clib_net_to_host_u16 (ikep->length);
500 for (i = 0; i < plen - 4; i++)
501 if (!isprint (ikep->payload[i]))
506 is_string ?
"string" :
"hex",
508 ikep->payload, plen - sizeof (*ikep));
515 u32 plen = clib_net_to_host_u16 (ikep->length);
517 u16 num_of_spi = clib_net_to_host_u16 (d->num_of_spi);
520 DBG_PLD (
"protocol_id %u spi_size %u num_of_spi %u len %u%s%U",
521 d->protocol_id, d->spi_size, num_of_spi,
522 plen, plen > sizeof (d) ?
" data " :
"",
535 del->protocol_id = d->protocol_id;
536 del->spi = clib_net_to_host_u32 (d->spi[i++]);
void ikev2_payload_add_nonce(ikev2_payload_chain_t *c, u8 *nonce)
#define IKEV2_PAYLOAD_NONCE
void ikev2_payload_add_notify(ikev2_payload_chain_t *c, u16 msg_type, u8 *data)
void ikev2_payload_add_sa(ikev2_payload_chain_t *c, ikev2_sa_proposal_t *proposals)
ikev2_sa_proposal_t * ikev2_parse_sa_payload(ike_payload_header_t *ikep)
#define clib_memcpy_fast(a, b, c)
ikev2_ts_t * ikev2_parse_ts_payload(ike_payload_header_t *ikep)
u8 * format_ikev2_sa_transform(u8 *s, va_list *args)
typedef CLIB_PACKED(struct{u8 nextpayload;u8 flags;u16 length;u8 protocol_id;u8 spi_size;u16 msg_type;u8 payload[0];})
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
void ikev2_payload_add_ke(ikev2_payload_chain_t *c, u16 dh_group, u8 *dh_data)
ikev2_notify_t * ikev2_parse_notify_payload(ike_payload_header_t *ikep)
#define clib_memcpy(d, s, n)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
#define IKEV2_PAYLOAD_DELETE
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
void ikev2_parse_vendor_payload(ike_payload_header_t *ikep)
void ikev2_payload_add_id(ikev2_payload_chain_t *c, ikev2_id_t *id, u8 type)
#define IKEV2_PAYLOAD_NOTIFY
ikev2_sa_transform_t * transforms
#define DBG_PLD(my_args...)
void ikev2_payload_add_delete(ikev2_payload_chain_t *c, ikev2_delete_t *d)
u8 * format_ikev2_notify_msg_type(u8 *s, va_list *args)
ikev2_auth_method_t method
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
static ike_payload_header_t * ikev2_payload_add_hdr(ikev2_payload_chain_t *c, u8 payload_type, int len)
void ikev2_payload_add_auth(ikev2_payload_chain_t *c, ikev2_auth_t *auth)
ikev2_protocol_id_t protocol_id
ike_delete_payload_header_t
u8 * format_ikev2_transform_type(u8 *s, va_list *args)
void ikev2_sa_free_proposal_vector(ikev2_sa_proposal_t **v)
#define IKEV2_PAYLOAD_AUTH
#define vec_append(v1, v2)
Append v2 after v1.
static void ikev2_payload_add_data(ikev2_payload_chain_t *c, u8 *data)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void ikev2_payload_chain_add_padding(ikev2_payload_chain_t *c, int bs)
#define vec_foreach(var, vec)
Vector iterator.
void ikev2_payload_add_ts(ikev2_payload_chain_t *c, ikev2_ts_t *ts, u8 type)
void ikev2_payload_add_notify_2(ikev2_payload_chain_t *c, u16 msg_type, u8 *data, ikev2_notify_t *notify)
ikev2_delete_t * ikev2_parse_delete_payload(ike_payload_header_t *ikep)