35 }) ike_notify_payload_header_t;
54 }) ike_ts_payload_header_t;
75 }) ike_sa_transform_data_t;
87 static ike_payload_header_t *
90 ike_payload_header_t * hdr = (ike_payload_header_t *) &c->
data[c->
last_hdr_off];
94 hdr->nextpayload = payload_type;
100 hdr = (ike_payload_header_t *) tmp;
103 hdr->length = clib_host_to_net_u16(len);
112 ike_payload_header_t * hdr;
116 len = clib_net_to_host_u16(hdr->length);
117 hdr->length = clib_host_to_net_u16(len +
vec_len(data));
123 ike_notify_payload_header_t * n;
126 n->msg_type = clib_host_to_net_u16(msg_type);
133 ike_payload_header_t * ph;
135 ike_sa_transform_data_t * tr;
150 prop->last_or_more = proposals - p + 1 <
vec_len(proposals) ? 2 : 0;
153 prop->spi_size = spi_size;
157 prop->spi[0] = clib_host_to_net_u32(p->
spi);
159 DBG_PLD(
"proposal num %u protocol_id %u last_or_more %u spi_size %u%s%U",
160 prop->proposal_num, prop->protocol_id, prop->last_or_more,
161 prop->spi_size, prop->spi_size ?
" spi_data " :
"",
167 tr = (ike_sa_transform_data_t *) tmp;
169 tr->transform_type = t->
type;
170 tr->transform_id = clib_host_to_net_u16(t->
transform_id);
171 tr->transform_len = clib_host_to_net_u16(
sizeof(*tr) +
vec_len(t->
attrs));
176 DBG_PLD(
"transform type %U transform_id %u last_or_more %u attr_size %u%s%U",
183 prop->proposal_len = clib_host_to_net_u16(
vec_len(tr_data) +
vec_len(pr_data));
194 ike_ke_payload_header_t * ke;
198 ke->dh_group = clib_host_to_net_u16(dh_group);
212 ike_id_payload_header_t * idp;
215 idp->id_type =
id->type;
236 dp->num_of_spi = clib_host_to_net_u16(num_of_spi);
240 u32 spi = clib_host_to_net_u32(d2->
spi);
251 ike_auth_payload_header_t * ap;
255 ap->auth_method = auth->
method;
262 ike_ts_payload_header_t * tsh;
264 u8 * data = 0, * tmp;
273 vec_add2(data, tmp,
sizeof(*entry));
277 entry->selector_len = clib_host_to_net_u16(16);
278 entry->start_port = clib_host_to_net_u16(ts2->
start_port);
279 entry->end_port = clib_host_to_net_u16(ts2->
end_port);
291 u8 * tmp __attribute__((unused));
304 u32 plen = clib_net_to_host_u16(ikep->length);
307 int proposal_ptr = 0;
315 DBG_PLD(
"proposal num %u len %u last_or_more %u id %u " 316 "spi_size %u num_transforms %u",
317 sap->proposal_num, clib_net_to_host_u16(sap->proposal_len),
318 sap->last_or_more, sap->protocol_id, sap->spi_size,
319 sap->num_transforms);
329 transform_ptr = proposal_ptr +
sizeof(*sap) + sap->spi_size;
335 if (sap->spi_size == 4) {
336 proposal->
spi = clib_net_to_host_u32(sap->spi[0]);
339 for(
i=0;
i< sap->num_transforms;
i++)
341 ike_sa_transform_data_t * tr = (ike_sa_transform_data_t *) &ikep->payload[transform_ptr];
342 u16 tlen = clib_net_to_host_u16(tr->transform_len);
344 if (tlen <
sizeof(*tr))
349 transform->
type = tr->transform_type;
350 transform->
transform_id = clib_net_to_host_u16(tr->transform_id);
351 if (tlen >
sizeof(*tr))
352 vec_add(transform->
attrs, tr->attributes, tlen -
sizeof(*tr));
354 DBG_PLD(
"transform num %u len %u last_or_more %u type %U id %u%s%U",
355 i, tlen, tr->last_or_more,
357 clib_net_to_host_u16(tr->transform_id),
358 tlen >
sizeof(*tr) ?
" attrs " :
"",
361 transform_ptr += tlen;
364 proposal_ptr += clib_net_to_host_u16(sap->proposal_len);
366 while (proposal_ptr < (plen -
sizeof(*ikep)) && sap->last_or_more == 2);
369 if (proposal_ptr != (plen -
sizeof(*ikep)) || sap->last_or_more)
375 DBG_PLD(
"SA payload data corrupted");
383 ike_ts_payload_header_t * tsp = (ike_ts_payload_header_t *) ikep;
387 for (i = 0; i < tsp->num_ts; i++)
389 if (tsp->ts[i].ts_type != 7)
391 DBG_PLD(
"unsupported TS type received (%u)", tsp->ts[i].ts_type);
396 ts->ts_type = tsp->ts[
i].ts_type;
397 ts->protocol_id = tsp->ts[
i].protocol_id;
398 ts->start_port = tsp->ts[
i].start_port;
399 ts->end_port = tsp->ts[
i].end_port;
400 ts->start_addr.as_u32 = tsp->ts[
i].start_addr.as_u32;
401 ts->end_addr.as_u32 = tsp->ts[
i].end_addr.as_u32;
409 ike_notify_payload_header_t * n = (ike_notify_payload_header_t *) ikep;
410 u32 plen = clib_net_to_host_u16(ikep->length);
414 DBG_PLD(
"msg_type %U len %u%s%U",
416 plen, plen >
sizeof(*n) ?
" data ":
"",
420 r->
msg_type = clib_net_to_host_u16(n->msg_type);
423 if (n->spi_size == 4)
426 r->
spi = clib_net_to_host_u32(spi);
429 else if (n->spi_size == 0)
438 if (plen > (
sizeof(*n) + n->spi_size))
440 vec_add(r->
data, n->payload + n->spi_size, plen -
sizeof(*n) - n->spi_size);
449 u32 plen = clib_net_to_host_u16(ikep->length);
453 for(i=0; i < plen - 4; i++)
454 if (!isprint(ikep->payload[i]))
459 is_string ?
"string":
"hex",
461 ikep->payload, plen -
sizeof(*ikep));
468 u32 plen = clib_net_to_host_u16(ikep->length);
470 u16 num_of_spi = clib_net_to_host_u16(d->num_of_spi);
473 DBG_PLD(
"protocol_id %u spi_size %u num_of_spi %u len %u%s%U",
474 d->protocol_id, d->spi_size, num_of_spi,
475 plen, plen >
sizeof(d) ?
" data ":
"",
488 del->protocol_id = d->protocol_id;
489 del->spi = clib_net_to_host_u32(d->spi[i++]);
void ikev2_payload_add_nonce(ikev2_payload_chain_t *c, u8 *nonce)
sll srl srl sll sra u16x4 i
#define IKEV2_PAYLOAD_NONCE
void ikev2_payload_add_notify(ikev2_payload_chain_t *c, u16 msg_type, u8 *data)
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
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
#define clib_warning(format, args...)
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_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)
ikev2_delete_t * ikev2_parse_delete_payload(ike_payload_header_t *ikep)