version 1.1.1.1, 2012/02/21 22:14:23
|
version 1.1.1.2, 2013/07/22 11:54:42
|
Line 107
|
Line 107
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
* |
* |
*/ |
*/ |
| #if 0 |
static inline void | static void |
__libnet_print_gre_flags_ver(u_int16_t fv) | __libnet_print_gre_flags_ver(uint16_t fv) |
{ |
{ |
printf("version = %d (%d) -> ", |
printf("version = %d (%d) -> ", |
fv & GRE_VERSION_MASK, libnet_getgre_length(fv)); |
fv & GRE_VERSION_MASK, libnet_getgre_length(fv)); |
Line 135 __libnet_print_gre_flags_ver(u_int16_t fv)
|
Line 135 __libnet_print_gre_flags_ver(u_int16_t fv)
|
} |
} |
printf("\n"); |
printf("\n"); |
} |
} |
|
#endif |
|
|
|
|
/* FIXME: what is the portability of the "((struct libnet_gre_hdr*)0)->" ? */ |
/* FIXME: what is the portability of the "((struct libnet_gre_hdr*)0)->" ? */ |
inline u_int32_t | uint32_t |
libnet_getgre_length(u_int16_t fv) | libnet_getgre_length(uint16_t fv) |
{ |
{ |
|
|
u_int32_t n = LIBNET_GRE_H; | uint32_t n = LIBNET_GRE_H; |
/* |
/* |
* If either the Checksum Present bit or the Routing Present bit are |
* If either the Checksum Present bit or the Routing Present bit are |
* set, BOTH the Checksum and Offset fields are present in the GRE |
* set, BOTH the Checksum and Offset fields are present in the GRE |
Line 172 libnet_getgre_length(u_int16_t fv)
|
Line 172 libnet_getgre_length(u_int16_t fv)
|
} |
} |
|
|
libnet_ptag_t |
libnet_ptag_t |
libnet_build_gre(u_int16_t fv, u_int16_t type, u_int16_t sum, | libnet_build_gre(uint16_t fv, uint16_t type, uint16_t sum, |
u_int16_t offset, u_int32_t key, u_int32_t seq, u_int16_t len, | uint16_t offset, uint32_t key, uint32_t seq, uint16_t len, |
u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag) | const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag) |
{ |
{ |
u_int32_t n; | uint32_t n; |
libnet_pblock_t *p; |
libnet_pblock_t *p; |
struct libnet_gre_hdr gre_hdr; |
struct libnet_gre_hdr gre_hdr; |
|
|
Line 199 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
Line 199 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
|
|
gre_hdr.flags_ver = htons(fv); |
gre_hdr.flags_ver = htons(fv); |
gre_hdr.type = htons(type); |
gre_hdr.type = htons(type); |
n = libnet_pblock_append(l, p, (u_int8_t *)&gre_hdr, LIBNET_GRE_H); | n = libnet_pblock_append(l, p, (uint8_t *)&gre_hdr, LIBNET_GRE_H); |
if (n == -1) |
if (n == -1) |
{ |
{ |
/* err msg set in libnet_pblock_append() */ |
/* err msg set in libnet_pblock_append() */ |
Line 210 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
Line 210 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
(fv & GRE_VERSION_MASK)) /* v1 */ |
(fv & GRE_VERSION_MASK)) /* v1 */ |
{ |
{ |
sum = htons(sum); |
sum = htons(sum); |
n = libnet_pblock_append(l, p, (u_int8_t*)&sum, | n = libnet_pblock_append(l, p, (uint8_t*)&sum, |
sizeof(gre_hdr.gre_sum)); |
sizeof(gre_hdr.gre_sum)); |
if (n == -1) |
if (n == -1) |
{ |
{ |
Line 218 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
Line 218 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
goto bad; |
goto bad; |
} |
} |
offset = htons(offset); |
offset = htons(offset); |
n = libnet_pblock_append(l, p, (u_int8_t*)&offset, | n = libnet_pblock_append(l, p, (uint8_t*)&offset, |
sizeof(gre_hdr.gre_offset)); |
sizeof(gre_hdr.gre_offset)); |
if (n == -1) |
if (n == -1) |
{ |
{ |
Line 231 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
Line 231 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
( (fv & GRE_VERSION_MASK) && (fv & GRE_SEQ)) ) /* v1 */ |
( (fv & GRE_VERSION_MASK) && (fv & GRE_SEQ)) ) /* v1 */ |
{ |
{ |
key = htonl(key); |
key = htonl(key); |
n = libnet_pblock_append(l, p, (u_int8_t*)&key, | n = libnet_pblock_append(l, p, (uint8_t*)&key, |
sizeof(gre_hdr.gre_key)); |
sizeof(gre_hdr.gre_key)); |
if (n == -1) |
if (n == -1) |
{ |
{ |
Line 244 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
Line 244 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
( (fv & GRE_VERSION_MASK) && (fv & GRE_ACK)) ) /* v1 */ |
( (fv & GRE_VERSION_MASK) && (fv & GRE_ACK)) ) /* v1 */ |
{ |
{ |
seq = htonl(seq); |
seq = htonl(seq); |
n = libnet_pblock_append(l, p, (u_int8_t*)&seq, | n = libnet_pblock_append(l, p, (uint8_t*)&seq, |
sizeof(gre_hdr.gre_seq)); |
sizeof(gre_hdr.gre_seq)); |
if (n == -1) |
if (n == -1) |
{ |
{ |
Line 253 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
Line 253 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
} |
} |
} |
} |
|
|
if ((payload && !payload_s) || (!payload && payload_s)) | /* boilerplate payload sanity check / append macro */ |
{ | LIBNET_DO_PAYLOAD(l, p); |
sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__); | |
goto bad; | |
} | |
|
|
if (payload && payload_s) |
|
{ |
|
n = libnet_pblock_append(l, p, payload, payload_s); |
|
if (n == -1) |
|
{ |
|
/* err msg set in libnet_pblock_append() */ |
|
goto bad; |
|
} |
|
} |
|
|
|
if ( (fv & GRE_CSUM) && (!sum) ) |
if ( (fv & GRE_CSUM) && (!sum) ) |
{ |
{ |
libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM); |
libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM); |
Line 282 bad:
|
Line 269 bad:
|
} |
} |
|
|
libnet_ptag_t |
libnet_ptag_t |
libnet_build_egre(u_int16_t fv, u_int16_t type, u_int16_t sum, | libnet_build_egre(uint16_t fv, uint16_t type, uint16_t sum, |
u_int16_t offset, u_int32_t key, u_int32_t seq, u_int16_t len, | uint16_t offset, uint32_t key, uint32_t seq, uint16_t len, |
u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag) | const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag) |
{ |
{ |
return (libnet_build_gre(fv, type, sum, offset, key, seq, len, |
return (libnet_build_gre(fv, type, sum, offset, key, seq, len, |
payload, payload_s, l, ptag)); |
payload, payload_s, l, ptag)); |
Line 309 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
Line 296 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
* |
* |
*/ |
*/ |
libnet_ptag_t |
libnet_ptag_t |
libnet_build_gre_sre(u_int16_t af, u_int8_t offset, u_int8_t length, | libnet_build_gre_sre(uint16_t af, uint8_t offset, uint8_t length, |
u_int8_t *routing, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | uint8_t *routing, const uint8_t *payload, uint32_t payload_s, libnet_t *l, |
libnet_ptag_t ptag) |
libnet_ptag_t ptag) |
{ |
{ |
u_int32_t n; | uint32_t n; |
libnet_pblock_t *p; |
libnet_pblock_t *p; |
struct libnet_gre_sre_hdr sre_hdr; |
struct libnet_gre_sre_hdr sre_hdr; |
|
|
Line 336 libnet_ptag_t ptag)
|
Line 323 libnet_ptag_t ptag)
|
sre_hdr.af = htons(af); |
sre_hdr.af = htons(af); |
sre_hdr.sre_offset = offset; |
sre_hdr.sre_offset = offset; |
sre_hdr.sre_length = length; |
sre_hdr.sre_length = length; |
n = libnet_pblock_append(l, p, (u_int8_t *)&sre_hdr, LIBNET_GRE_SRE_H); | n = libnet_pblock_append(l, p, (uint8_t *)&sre_hdr, LIBNET_GRE_SRE_H); |
if (n == -1) |
if (n == -1) |
{ |
{ |
/* err msg set in libnet_pblock_append() */ |
/* err msg set in libnet_pblock_append() */ |
Line 359 libnet_ptag_t ptag)
|
Line 346 libnet_ptag_t ptag)
|
} |
} |
} |
} |
|
|
if ((payload && !payload_s) || (!payload && payload_s)) | /* boilerplate payload sanity check / append macro */ |
{ | LIBNET_DO_PAYLOAD(l, p); |
sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__); | |
goto bad; | |
} | |
|
|
if (payload && payload_s) |
|
{ |
|
n = libnet_pblock_append(l, p, payload, payload_s); |
|
if (n == -1) |
|
{ |
|
/* err msg set in libnet_pblock_append() */ |
|
goto bad; |
|
} |
|
} |
|
|
|
return (ptag ? ptag : libnet_pblock_update(l, p, 0, |
return (ptag ? ptag : libnet_pblock_update(l, p, 0, |
LIBNET_PBLOCK_GRE_SRE_H)); |
LIBNET_PBLOCK_GRE_SRE_H)); |
|
|
Line 387 bad:
|
Line 361 bad:
|
libnet_ptag_t |
libnet_ptag_t |
libnet_build_gre_last_sre(libnet_t *l, libnet_ptag_t ptag) |
libnet_build_gre_last_sre(libnet_t *l, libnet_ptag_t ptag) |
{ |
{ |
u_int32_t n, zero = 0; | uint32_t n, zero = 0; |
libnet_pblock_t *p; |
libnet_pblock_t *p; |
|
|
if (l == NULL) |
if (l == NULL) |
Line 407 libnet_build_gre_last_sre(libnet_t *l, libnet_ptag_t p
|
Line 381 libnet_build_gre_last_sre(libnet_t *l, libnet_ptag_t p
|
return (-1); |
return (-1); |
} |
} |
|
|
n = libnet_pblock_append(l, p, (u_int8_t *)&zero, LIBNET_GRE_SRE_H); | n = libnet_pblock_append(l, p, (uint8_t *)&zero, LIBNET_GRE_SRE_H); |
if (n == -1) |
if (n == -1) |
{ |
{ |
/* err msg set in libnet_pblock_append() */ |
/* err msg set in libnet_pblock_append() */ |
Line 422 bad:
|
Line 396 bad:
|
return (-1); |
return (-1); |
|
|
} |
} |
|
|
|
|
/* EOF */ |
/* EOF */ |