36 u8 payload[0];}) ike_notify_payload_header_t;
60 ike_ts_payload_header_t;
71 u8 num_transforms;
u32 spi[0];
84 }) ike_sa_transform_data_t;
99 static ike_payload_header_t *
102 ike_payload_header_t *hdr =
107 hdr->nextpayload = payload_type;
113 hdr = (ike_payload_header_t *) tmp;
114 memset (hdr, 0, len);
116 hdr->length = clib_host_to_net_u16 (len);
125 ike_payload_header_t *hdr;
129 len = clib_net_to_host_u16 (hdr->length);
130 hdr->length = clib_host_to_net_u16 (len +
vec_len (data));
143 ike_notify_payload_header_t *n;
149 n->msg_type = clib_host_to_net_u16 (msg_type);
165 ike_payload_header_t *ph;
167 ike_sa_transform_data_t *tr;
182 prop->last_or_more = proposals - p + 1 <
vec_len (proposals) ? 2 : 0;
185 prop->spi_size = spi_size;
189 prop->spi[0] = clib_host_to_net_u32 (p->
spi);
191 DBG_PLD (
"proposal num %u protocol_id %u last_or_more %u spi_size %u%s%U",
192 prop->proposal_num, prop->protocol_id, prop->last_or_more,
193 prop->spi_size, prop->spi_size ?
" spi_data " :
"",
199 tr = (ike_sa_transform_data_t *) tmp;
202 tr->transform_type = t->
type;
203 tr->transform_id = clib_host_to_net_u16 (t->
transform_id);
205 clib_host_to_net_u16 (
sizeof (*tr) +
vec_len (t->
attrs));
211 (
"transform type %U transform_id %u last_or_more %u attr_size %u%s%U",
230 ike_ke_payload_header_t *ke;
234 ke->dh_group = clib_host_to_net_u16 (dh_group);
242 sizeof (ike_payload_header_t));
249 ike_id_payload_header_t *idp;
254 idp->id_type =
id->type;
277 dp->num_of_spi = clib_host_to_net_u16 (num_of_spi);
281 u32 spi = clib_host_to_net_u32 (d2->
spi);
292 ike_auth_payload_header_t *ap;
298 ap->auth_method = auth->
method;
305 ike_ts_payload_header_t *tsh;
318 vec_add2 (data, tmp,
sizeof (*entry));
322 entry->selector_len = clib_host_to_net_u16 (16);
323 entry->start_port = clib_host_to_net_u16 (ts2->
start_port);
324 entry->end_port = clib_host_to_net_u16 (ts2->
end_port);
336 u8 *tmp __attribute__ ((unused));
349 u32 plen = clib_net_to_host_u16 (ikep->length);
352 int proposal_ptr = 0;
360 DBG_PLD (
"proposal num %u len %u last_or_more %u id %u " 361 "spi_size %u num_transforms %u",
362 sap->proposal_num, clib_net_to_host_u16 (sap->proposal_len),
363 sap->last_or_more, sap->protocol_id, sap->spi_size,
364 sap->num_transforms);
374 transform_ptr = proposal_ptr +
sizeof (*sap) + sap->spi_size;
380 if (sap->spi_size == 4)
382 proposal->
spi = clib_net_to_host_u32 (sap->spi[0]);
385 for (
i = 0;
i < sap->num_transforms;
i++)
387 ike_sa_transform_data_t *tr =
388 (ike_sa_transform_data_t *) & ikep->payload[transform_ptr];
389 u16 tlen = clib_net_to_host_u16 (tr->transform_len);
391 if (tlen <
sizeof (*tr))
396 transform->
type = tr->transform_type;
397 transform->
transform_id = clib_net_to_host_u16 (tr->transform_id);
398 if (tlen >
sizeof (*tr))
399 vec_add (transform->
attrs, tr->attributes, tlen - sizeof (*tr));
402 (
"transform num %u len %u last_or_more %u type %U id %u%s%U",
i,
404 clib_net_to_host_u16 (tr->transform_id),
406 tr->attributes, tlen - sizeof (*tr));
408 transform_ptr += tlen;
411 proposal_ptr += clib_net_to_host_u16 (sap->proposal_len);
413 while (proposal_ptr < (plen -
sizeof (*ikep)) && sap->last_or_more == 2);
416 if (proposal_ptr != (plen -
sizeof (*ikep)) || sap->last_or_more)
422 DBG_PLD (
"SA payload data corrupted");
430 ike_ts_payload_header_t *tsp = (ike_ts_payload_header_t *) ikep;
434 for (i = 0; i < tsp->num_ts; i++)
436 if (tsp->ts[i].ts_type != 7)
438 DBG_PLD (
"unsupported TS type received (%u)", tsp->ts[i].ts_type);
443 ts->ts_type = tsp->ts[
i].ts_type;
444 ts->protocol_id = tsp->ts[
i].protocol_id;
445 ts->start_port = tsp->ts[
i].start_port;
446 ts->end_port = tsp->ts[
i].end_port;
447 ts->start_addr.as_u32 = tsp->ts[
i].start_addr.as_u32;
448 ts->end_addr.as_u32 = tsp->ts[
i].end_addr.as_u32;
456 ike_notify_payload_header_t *n = (ike_notify_payload_header_t *) ikep;
457 u32 plen = clib_net_to_host_u16 (ikep->length);
461 DBG_PLD (
"msg_type %U len %u%s%U",
463 plen, plen > sizeof (*n) ?
" data " :
"",
467 r->
msg_type = clib_net_to_host_u16 (n->msg_type);
470 if (n->spi_size == 4)
473 r->
spi = clib_net_to_host_u32 (spi);
476 else if (n->spi_size == 0)
485 if (plen > (
sizeof (*n) + n->spi_size))
488 plen - sizeof (*n) - n->spi_size);
497 u32 plen = clib_net_to_host_u16 (ikep->length);
501 for (i = 0; i < plen - 4; i++)
502 if (!isprint (ikep->payload[i]))
507 is_string ?
"string" :
"hex",
509 ikep->payload, plen - sizeof (*ikep));
516 u32 plen = clib_net_to_host_u16 (ikep->length);
518 u16 num_of_spi = clib_net_to_host_u16 (d->num_of_spi);
521 DBG_PLD (
"protocol_id %u spi_size %u num_of_spi %u len %u%s%U",
522 d->protocol_id, d->spi_size, num_of_spi,
523 plen, plen > sizeof (d) ?
" data " :
"",
536 del->protocol_id = d->protocol_id;
537 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)
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.
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 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...)
#define clib_memcpy(a, b, c)
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)