File: idiomatic

package info (click to toggle)
tcng 10b-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 3,636 kB
  • ctags: 2,515
  • sloc: ansic: 19,040; pascal: 4,640; yacc: 2,619; sh: 1,914; perl: 1,546; lex: 772; makefile: 756
file content (254 lines) | stat: -rw-r--r-- 6,913 bytes parent folder | download | duplicates (5)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# idiomatic: ip_is_fragment ---------------------------------------------------
tcsim -n -s 2 | sed '/ D /s/.*: //p;d'
dev "eth0" 10000 {
    #include "fields.tc"
    #include "ip.def"

    dsmark {
	class (0,value 0xff) if ip_is_fragment;
	class (1) if 1;
    }
}

/*
 * Instead of marking, this script originally dropped selected packets.
 * That's why the pattern "dead" is used to mark classified packets.
 */

send 0x45 0 0 0  0 0 0 0  1 ICMP 0 0  nl:0 x 4		  // no fragment
send 0x45 0 0 0  0 0 0 2  1 ICMP 0 0  nl:0 x 4 ns:0xdead  // non-zero offset
send 0x45 0 0 0  0 0 0 3  1 ICMP 0 0  nl:0 x 4 ns:0xdead  // non-zero offset
send 0x45 0 0 0  0 0 0 4  1 ICMP 0 0  nl:0 x 4 ns:0xdead  // non-zero offset
send 0x45 0 0 0  0 0 0 5  1 ICMP 0 0  nl:0 x 4 ns:0xdead  // non-zero offset
send 0x45 0 0 0  0 0 0x40 0  1 ICMP 0 0  nl:0 x 4 	    // ip_DF set
send 0x45 0 0 0  0 0 0x20 0  1 ICMP 0 0  nl:0 x 4 ns:0xdead // ip_MF set
end
EOF
4500 ...
45ff ...
45ff ...
45ff ...
45ff ...
4500 ...
45ff ...
# idiomatic: not_ip_is_fragment -----------------------------------------------
tcsim -n -s 2 | sed '/ D /s/.*: //p;d'
dev "eth0" 10000 {
    #include "fields.tc"
    #include "ip.def"

    dsmark {
	class (0,value 0xff) if not_ip_is_fragment;
	class (1) if 1;
    }
}

/*
 * Instead of marking, this script originally dropped packets that weren't
 * selected. That's why the pattern "dead" is used to mark unclassified
 * packets. (Note that this is exactly the contrary to the previous test
 * case.)
 */

send 0x45 0 0 0  0 0 0 0  1 ICMP 0 0  nl:0 x 4		  // no fragment
send 0x45 0 0 0  0 0 0 2  1 ICMP 0 0  nl:0 x 4 ns:0xdead  // non-zero offset
send 0x45 0 0 0  0 0 0 3  1 ICMP 0 0  nl:0 x 4 ns:0xdead  // non-zero offset
send 0x45 0 0 0  0 0 0 4  1 ICMP 0 0  nl:0 x 4 ns:0xdead  // non-zero offset
send 0x45 0 0 0  0 0 0 5  1 ICMP 0 0  nl:0 x 4 ns:0xdead  // non-zero offset
send 0x45 0 0 0  0 0 0x40 0  1 ICMP 0 0  nl:0 x 4 	    // ip_DF set
send 0x45 0 0 0  0 0 0x20 0  1 ICMP 0 0  nl:0 x 4 ns:0xdead // ip_MF set
end
EOF
45ff ...
4500 ...
4500 ...
4500 ...
4500 ...
45ff ...
4500 ...
# idiomatic: ip_has_options ---------------------------------------------------
tcsim -s 2 | sed '/ D /s/.*: //p;d'
dev "eth0" 10000 {
    #include "fields.tc"

    dsmark {
	class (0,value 0xff) if ip_has_options;
	class (1) if 1;
    }
}

send 0x45 0 0 0  nl:0 x 10		// no options
send 0x46 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x47 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x48 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x49 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x4a 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x4b 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x4c 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x4d 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x4e 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x4f 0 0 0  nl:0 x 10 ns:0xdead	// has options
end
EOF
4500 ...
46ff ...
47ff ...
48ff ...
49ff ...
4aff ...
4bff ...
4cff ...
4dff ...
4eff ...
4fff ...
# idiomatic: not_ip_has_options -----------------------------------------------
tcsim -s 2 | sed '/ D /s/.*: //p;d'
dev "eth0" 10000 {
    #include "fields.tc"

    dsmark {
	class (0,value 0xff) if not_ip_has_options;
	class (1) if 1;
    }
}

send 0x45 0 0 0  nl:0 x 10		// no options
send 0x46 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x47 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x48 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x49 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x4a 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x4b 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x4c 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x4d 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x4e 0 0 0  nl:0 x 10 ns:0xdead	// has options
send 0x4f 0 0 0  nl:0 x 10 ns:0xdead	// has options
end
EOF
45ff ...
4600 ...
4700 ...
4800 ...
4900 ...
4a00 ...
4b00 ...
4c00 ...
4d00 ...
4e00 ...
4f00 ...
# idiomatic: ip_is_tiny_fragment ----------------------------------------------
tcsim -n -s 2 | sed '/ D /s/.*: //p;d'
dev "eth0" 10000 {
    #include "fields.tc"
    #include "ip.def"

    dsmark {
	class (0,value 0xff) if ip_is_tiny_fragment;
	class (1) if 1;
    }
}

send 0x45 0 0 0  0 0 0 0  1 ICMP 0 0  nl:1 nl:2  ns:0 0 x 2	// normal ICMP
send 0x45 0 0 0  0 0 0 0  1 ICMP 0 0  nl:1 nl:2  ns:0xdead 0	// tiny ICMP
send 0x45 0 0 0  0 0 0 0  1 TCP  0 0  nl:1 nl:2  ns:0 0 x 18	// normal TCP
send 0x45 0 0 0  0 0 0 0  1 TCP  0 0  nl:1 nl:2  ns:0xdead 0 x 17 // tiny TCP
send 0x45 0 0 0  0 0 0 0  1 UDP  0 0  nl:1 nl:2  ns:0 0 x 6	// normal UDP
send 0x45 0 0 0  0 0 0 0  1 UDP  0 0  nl:1 nl:2  ns:0xdead 0 x 5 // tiny UDP
send 0x45 0 0 0  0 0 0 1  1 ICMP 0 0  nl:1 nl:2  ns:0xdead x 10 // ip_off == 1
end
EOF
4500 ...
45ff ...
4500 ...
45ff ...
4500 ...
45ff ...
45ff ...
# idiomatic: not_ip_is_tiny_fragment ------------------------------------------
tcsim -n -s 2 | sed '/ D /s/.*: //p;d'
dev "eth0" 10000 {
    #include "fields.tc"
    #include "ip.def"

    dsmark {
	class (0,value 0xff) if not_ip_is_tiny_fragment;
	class (1) if 1;
    }
}

send 0x45 0 0 0  0 0 0 0  1 ICMP 0 0  nl:1 nl:2  ns:0 0 x 2	// normal ICMP
send 0x45 0 0 0  0 0 0 0  1 ICMP 0 0  nl:1 nl:2  ns:0xdead 0	// tiny ICMP
send 0x45 0 0 0  0 0 0 0  1 TCP  0 0  nl:1 nl:2  ns:0 0 x 18	// normal TCP
send 0x45 0 0 0  0 0 0 0  1 TCP  0 0  nl:1 nl:2  ns:0xdead 0 x 17 // tiny TCP
send 0x45 0 0 0  0 0 0 0  1 UDP  0 0  nl:1 nl:2  ns:0 0 x 6	// normal UDP
send 0x45 0 0 0  0 0 0 0  1 UDP  0 0  nl:1 nl:2  ns:0xdead 0 x 5 // tiny UDP
send 0x45 0 0 0  0 0 0 1  1 ICMP 0 0  nl:1 nl:2  ns:0xdead x 10 // ip_off == 1
end
EOF
45ff ...
4500 ...
45ff ...
4500 ...
45ff ...
4500 ...
4500 ...
# idiomatic: tcp_incoming -----------------------------------------------------
tcsim -n -s 2 | sed '/ D /s/.*: //p;d'
dev "eth0" 10000 {
    #include "fields.tc"
    #include "ip.def"

    dsmark {
	class (0,value 0xff) if tcp_incoming;
	class (1) if 1;
    }
}

$src = 1.2.3.4
$dst = 5.6.7.8
$sport = PORT_USER
$dport = PORT_HTTP

#define NOTHING
send TCP_PCK($flag = 0)					// no flags
send TCP_PCK($flag = TCP_SYN)		ns:0xdead	// SYN
send TCP_PCK($flag = TCP_SYN | TCP_ACK)			// SYN+ACK
send TCP_PCK($flag = TCP_ACK)				// ACK
send UDP_PCK(NOTHING)					// not TCP
end
EOF
4500 ...
45ff ...
4500 ...
4500 ...
4500 ...
# idiomatic: not_tcp_incoming -------------------------------------------------
tcsim -n -s 2 | sed '/ D /s/.*: //p;d'
dev "eth0" 10000 {
    #include "fields.tc"
    #include "ip.def"

    dsmark {
	class (0,value 0xff) if not_tcp_incoming;
	class (1) if 1;
    }
}

$src = 1.2.3.4
$dst = 5.6.7.8
$sport = PORT_USER
$dport = PORT_HTTP

#define NOTHING
send TCP_PCK($flag = 0)					// no flags
send TCP_PCK($flag = TCP_SYN)		ns:0xdead	// SYN
send TCP_PCK($flag = TCP_SYN | TCP_ACK)			// SYN+ACK
send TCP_PCK($flag = TCP_ACK)				// ACK
send UDP_PCK(NOTHING)					// not TCP
end
EOF
45ff ...
4500 ...
45ff ...
45ff ...
45ff ...