-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdsr-opt.h
111 lines (91 loc) · 2.63 KB
/
dsr-opt.h
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
/* Copyright (C) Uppsala University
*
* This file is distributed under the terms of the GNU general Public
* License (GPL), see the file LICENSE
*
* Author: Erik Nordström, <[email protected]>
*/
#ifndef _DSR_OPT_H
#define _DSR_OPT_H
#ifdef NS2
#include <packet.h>
#include "endian.h"
#endif
#include "dsr.h"
#ifndef NO_GLOBALS
/* Generic header for all options */
struct dsr_opt {
u_int8_t type;
u_int8_t length;
};
/* The DSR options header (always comes first) */
struct dsr_opt_hdr {
u_int8_t nh;
#if defined(__LITTLE_ENDIAN_BITFIELD)
u_int8_t res:7;
u_int8_t f:1;
#elif defined (__BIG_ENDIAN_BITFIELD)
u_int8_t f:1;
u_int8_t res:7;
#else
#error "Please fix <asm/byteorder.h>"
#endif
u_int16_t p_len; /* payload length */
#ifdef NS2
static int offset_;
inline static int &offset() {
return offset_;
}
inline static dsr_opt_hdr *access(const Packet * p) {
return (dsr_opt_hdr *) p->access(offset_);
}
int size() {
return p_len + sizeof(struct dsr_opt_hdr);
}
#endif /* NS2 */
struct dsr_opt option[0];
};
struct dsr_pad1_opt {
u_int8_t type;
};
#ifdef NS2
#define DSR_NO_NEXT_HDR_TYPE PT_NTYPE
#else
#define DSR_NO_NEXT_HDR_TYPE 0
#endif
/* Header lengths */
#define DSR_FIXED_HDR_LEN 4 /* Should be the same as DSR_OPT_HDR_LEN, but that
* is not the case in ns-2 */
#define DSR_OPT_HDR_LEN sizeof(struct dsr_opt_hdr)
#define DSR_OPT_PAD1_LEN 1
#define DSR_PKT_MIN_LEN 24 /* IP header + DSR header = 20 + 4 */
/* Header types */
#define DSR_OPT_PADN 0
#define DSR_OPT_RREP 1
#define DSR_OPT_RREQ 2
#define DSR_OPT_RERR 3
#define DSR_OPT_PREV_HOP 5
#define DSR_OPT_ACK 32
#define DSR_OPT_SRT 96
#define DSR_OPT_TIMEOUT 128
#define DSR_OPT_FLOWID 129
#define DSR_OPT_ACK_REQ 160
#define DSR_OPT_PAD1 224
/* #define DSR_FIXED_HDR(iph) (struct dsr_opt_hdr *)((char *)iph + (iph->ihl << 2)) */
#define DSR_GET_OPT(opt_hdr) ((struct dsr_opt *)(((char *)opt_hdr) + DSR_OPT_HDR_LEN))
#define DSR_GET_NEXT_OPT(dopt) ((struct dsr_opt *)((char *)dopt + dopt->length + 2))
#define DSR_LAST_OPT(dp, opt) ((dp->dh.raw + ntohs(dp->dh.opth->p_len) + 4) == ((char *)opt + opt->length + 2))
struct dsr_opt_hdr *dsr_opt_hdr_add(char *buf, unsigned int len, unsigned int protocol);
struct dsr_opt *dsr_opt_find_opt(struct dsr_pkt *dp, int type);
int dsr_opt_parse(struct dsr_pkt *dp);
#ifdef __KERNEL__
struct iphdr *dsr_build_ip(struct dsr_pkt *dp, struct in_addr src,
struct in_addr dst, int ip_len, int totlen,
int protocol, int ttl);
#endif
#endif /* NO_GLOBALS */
#ifndef NO_DECLS
int dsr_opt_remove(struct dsr_pkt *dp);
int dsr_opt_recv(struct dsr_pkt *dp);
#endif /* NO_DECLS */
#endif