1*8b26181fSAndroid Build Coastguard Worker /*
2*8b26181fSAndroid Build Coastguard Worker * Copyright (c) 1990, 1991, 1992, 1994, 1995, 1996
3*8b26181fSAndroid Build Coastguard Worker * The Regents of the University of California. All rights reserved.
4*8b26181fSAndroid Build Coastguard Worker *
5*8b26181fSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without
6*8b26181fSAndroid Build Coastguard Worker * modification, are permitted provided that: (1) source code distributions
7*8b26181fSAndroid Build Coastguard Worker * retain the above copyright notice and this paragraph in its entirety, (2)
8*8b26181fSAndroid Build Coastguard Worker * distributions including binary code include the above copyright notice and
9*8b26181fSAndroid Build Coastguard Worker * this paragraph in its entirety in the documentation or other materials
10*8b26181fSAndroid Build Coastguard Worker * provided with the distribution, and (3) all advertising materials mentioning
11*8b26181fSAndroid Build Coastguard Worker * features or use of this software display the following acknowledgement:
12*8b26181fSAndroid Build Coastguard Worker * ``This product includes software developed by the University of California,
13*8b26181fSAndroid Build Coastguard Worker * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14*8b26181fSAndroid Build Coastguard Worker * the University nor the names of its contributors may be used to endorse
15*8b26181fSAndroid Build Coastguard Worker * or promote products derived from this software without specific prior
16*8b26181fSAndroid Build Coastguard Worker * written permission.
17*8b26181fSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18*8b26181fSAndroid Build Coastguard Worker * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19*8b26181fSAndroid Build Coastguard Worker * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20*8b26181fSAndroid Build Coastguard Worker */
21*8b26181fSAndroid Build Coastguard Worker
22*8b26181fSAndroid Build Coastguard Worker #ifdef HAVE_CONFIG_H
23*8b26181fSAndroid Build Coastguard Worker #include <config.h>
24*8b26181fSAndroid Build Coastguard Worker #endif
25*8b26181fSAndroid Build Coastguard Worker
26*8b26181fSAndroid Build Coastguard Worker #include <pcap-types.h>
27*8b26181fSAndroid Build Coastguard Worker
28*8b26181fSAndroid Build Coastguard Worker #include <stdio.h>
29*8b26181fSAndroid Build Coastguard Worker #include <string.h>
30*8b26181fSAndroid Build Coastguard Worker
31*8b26181fSAndroid Build Coastguard Worker #ifdef __linux__
32*8b26181fSAndroid Build Coastguard Worker #include <linux/types.h>
33*8b26181fSAndroid Build Coastguard Worker #include <linux/if_packet.h>
34*8b26181fSAndroid Build Coastguard Worker #include <linux/filter.h>
35*8b26181fSAndroid Build Coastguard Worker
36*8b26181fSAndroid Build Coastguard Worker /*
37*8b26181fSAndroid Build Coastguard Worker * We want our versions of these #defines, not Linux's version.
38*8b26181fSAndroid Build Coastguard Worker * (The two should be the same; if not, we have a problem; all BPF
39*8b26181fSAndroid Build Coastguard Worker * implementations *should* be source-compatible supersets of ours.)
40*8b26181fSAndroid Build Coastguard Worker */
41*8b26181fSAndroid Build Coastguard Worker #undef BPF_STMT
42*8b26181fSAndroid Build Coastguard Worker #undef BPF_JUMP
43*8b26181fSAndroid Build Coastguard Worker #endif
44*8b26181fSAndroid Build Coastguard Worker
45*8b26181fSAndroid Build Coastguard Worker #include "pcap-int.h"
46*8b26181fSAndroid Build Coastguard Worker
47*8b26181fSAndroid Build Coastguard Worker #ifdef HAVE_OS_PROTO_H
48*8b26181fSAndroid Build Coastguard Worker #include "os-proto.h"
49*8b26181fSAndroid Build Coastguard Worker #endif
50*8b26181fSAndroid Build Coastguard Worker
51*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_OFF
52*8b26181fSAndroid Build Coastguard Worker /*
53*8b26181fSAndroid Build Coastguard Worker * Symbolic names for offsets that refer to the special Linux BPF locations.
54*8b26181fSAndroid Build Coastguard Worker */
55*8b26181fSAndroid Build Coastguard Worker static const char *offsets[SKF_AD_MAX] = {
56*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_PROTOCOL
57*8b26181fSAndroid Build Coastguard Worker [SKF_AD_PROTOCOL] = "proto",
58*8b26181fSAndroid Build Coastguard Worker #endif
59*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_PKTTYPE
60*8b26181fSAndroid Build Coastguard Worker [SKF_AD_PKTTYPE] = "type",
61*8b26181fSAndroid Build Coastguard Worker #endif
62*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_IFINDEX
63*8b26181fSAndroid Build Coastguard Worker [SKF_AD_IFINDEX] = "ifidx",
64*8b26181fSAndroid Build Coastguard Worker #endif
65*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_NLATTR
66*8b26181fSAndroid Build Coastguard Worker [SKF_AD_NLATTR] = "nla",
67*8b26181fSAndroid Build Coastguard Worker #endif
68*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_NLATTR_NEST
69*8b26181fSAndroid Build Coastguard Worker [SKF_AD_NLATTR_NEST] = "nlan",
70*8b26181fSAndroid Build Coastguard Worker #endif
71*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_MARK
72*8b26181fSAndroid Build Coastguard Worker [SKF_AD_MARK] = "mark",
73*8b26181fSAndroid Build Coastguard Worker #endif
74*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_QUEUE
75*8b26181fSAndroid Build Coastguard Worker [SKF_AD_QUEUE] = "queue",
76*8b26181fSAndroid Build Coastguard Worker #endif
77*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_HATYPE
78*8b26181fSAndroid Build Coastguard Worker [SKF_AD_HATYPE] = "hatype",
79*8b26181fSAndroid Build Coastguard Worker #endif
80*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_RXHASH
81*8b26181fSAndroid Build Coastguard Worker [SKF_AD_RXHASH] = "rxhash",
82*8b26181fSAndroid Build Coastguard Worker #endif
83*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_CPU
84*8b26181fSAndroid Build Coastguard Worker [SKF_AD_CPU] = "cpu",
85*8b26181fSAndroid Build Coastguard Worker #endif
86*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_ALU_XOR_X
87*8b26181fSAndroid Build Coastguard Worker [SKF_AD_ALU_XOR_X] = "xor_x",
88*8b26181fSAndroid Build Coastguard Worker #endif
89*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_VLAN_TAG
90*8b26181fSAndroid Build Coastguard Worker [SKF_AD_VLAN_TAG] = "vlan_tci",
91*8b26181fSAndroid Build Coastguard Worker #endif
92*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_VLAN_TAG_PRESENT
93*8b26181fSAndroid Build Coastguard Worker [SKF_AD_VLAN_TAG_PRESENT] = "vlanp",
94*8b26181fSAndroid Build Coastguard Worker #endif
95*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_PAY_OFFSET
96*8b26181fSAndroid Build Coastguard Worker [SKF_AD_PAY_OFFSET] = "poff",
97*8b26181fSAndroid Build Coastguard Worker #endif
98*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_RANDOM
99*8b26181fSAndroid Build Coastguard Worker [SKF_AD_RANDOM] = "random",
100*8b26181fSAndroid Build Coastguard Worker #endif
101*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_VLAN_TPID
102*8b26181fSAndroid Build Coastguard Worker [SKF_AD_VLAN_TPID] = "vlan_tpid"
103*8b26181fSAndroid Build Coastguard Worker #endif
104*8b26181fSAndroid Build Coastguard Worker };
105*8b26181fSAndroid Build Coastguard Worker #endif
106*8b26181fSAndroid Build Coastguard Worker
107*8b26181fSAndroid Build Coastguard Worker static void
bpf_print_abs_load_operand(char * buf,size_t bufsize,const struct bpf_insn * p)108*8b26181fSAndroid Build Coastguard Worker bpf_print_abs_load_operand(char *buf, size_t bufsize, const struct bpf_insn *p)
109*8b26181fSAndroid Build Coastguard Worker {
110*8b26181fSAndroid Build Coastguard Worker #ifdef SKF_AD_OFF
111*8b26181fSAndroid Build Coastguard Worker const char *sym;
112*8b26181fSAndroid Build Coastguard Worker
113*8b26181fSAndroid Build Coastguard Worker /*
114*8b26181fSAndroid Build Coastguard Worker * It's an absolute load.
115*8b26181fSAndroid Build Coastguard Worker * Is the offset a special Linux offset that we know about?
116*8b26181fSAndroid Build Coastguard Worker */
117*8b26181fSAndroid Build Coastguard Worker if (p->k >= (bpf_u_int32)SKF_AD_OFF &&
118*8b26181fSAndroid Build Coastguard Worker p->k < (bpf_u_int32)(SKF_AD_OFF + SKF_AD_MAX) &&
119*8b26181fSAndroid Build Coastguard Worker (sym = offsets[p->k - (bpf_u_int32)SKF_AD_OFF]) != NULL) {
120*8b26181fSAndroid Build Coastguard Worker /*
121*8b26181fSAndroid Build Coastguard Worker * Yes. Print the offset symbolically.
122*8b26181fSAndroid Build Coastguard Worker */
123*8b26181fSAndroid Build Coastguard Worker (void)snprintf(buf, bufsize, "[%s]", sym);
124*8b26181fSAndroid Build Coastguard Worker } else
125*8b26181fSAndroid Build Coastguard Worker #endif
126*8b26181fSAndroid Build Coastguard Worker (void)snprintf(buf, bufsize, "[%d]", p->k);
127*8b26181fSAndroid Build Coastguard Worker }
128*8b26181fSAndroid Build Coastguard Worker
129*8b26181fSAndroid Build Coastguard Worker char *
bpf_image(const struct bpf_insn * p,int n)130*8b26181fSAndroid Build Coastguard Worker bpf_image(const struct bpf_insn *p, int n)
131*8b26181fSAndroid Build Coastguard Worker {
132*8b26181fSAndroid Build Coastguard Worker const char *op;
133*8b26181fSAndroid Build Coastguard Worker static char image[256];
134*8b26181fSAndroid Build Coastguard Worker char operand_buf[64];
135*8b26181fSAndroid Build Coastguard Worker const char *operand;
136*8b26181fSAndroid Build Coastguard Worker
137*8b26181fSAndroid Build Coastguard Worker switch (p->code) {
138*8b26181fSAndroid Build Coastguard Worker
139*8b26181fSAndroid Build Coastguard Worker default:
140*8b26181fSAndroid Build Coastguard Worker op = "unimp";
141*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "0x%x", p->code);
142*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
143*8b26181fSAndroid Build Coastguard Worker break;
144*8b26181fSAndroid Build Coastguard Worker
145*8b26181fSAndroid Build Coastguard Worker case BPF_RET|BPF_K:
146*8b26181fSAndroid Build Coastguard Worker op = "ret";
147*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#%d", p->k);
148*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
149*8b26181fSAndroid Build Coastguard Worker break;
150*8b26181fSAndroid Build Coastguard Worker
151*8b26181fSAndroid Build Coastguard Worker case BPF_RET|BPF_A:
152*8b26181fSAndroid Build Coastguard Worker op = "ret";
153*8b26181fSAndroid Build Coastguard Worker operand = "";
154*8b26181fSAndroid Build Coastguard Worker break;
155*8b26181fSAndroid Build Coastguard Worker
156*8b26181fSAndroid Build Coastguard Worker case BPF_LD|BPF_W|BPF_ABS:
157*8b26181fSAndroid Build Coastguard Worker op = "ld";
158*8b26181fSAndroid Build Coastguard Worker bpf_print_abs_load_operand(operand_buf, sizeof operand_buf, p);
159*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
160*8b26181fSAndroid Build Coastguard Worker break;
161*8b26181fSAndroid Build Coastguard Worker
162*8b26181fSAndroid Build Coastguard Worker case BPF_LD|BPF_H|BPF_ABS:
163*8b26181fSAndroid Build Coastguard Worker op = "ldh";
164*8b26181fSAndroid Build Coastguard Worker bpf_print_abs_load_operand(operand_buf, sizeof operand_buf, p);
165*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
166*8b26181fSAndroid Build Coastguard Worker break;
167*8b26181fSAndroid Build Coastguard Worker
168*8b26181fSAndroid Build Coastguard Worker case BPF_LD|BPF_B|BPF_ABS:
169*8b26181fSAndroid Build Coastguard Worker op = "ldb";
170*8b26181fSAndroid Build Coastguard Worker bpf_print_abs_load_operand(operand_buf, sizeof operand_buf, p);
171*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
172*8b26181fSAndroid Build Coastguard Worker break;
173*8b26181fSAndroid Build Coastguard Worker
174*8b26181fSAndroid Build Coastguard Worker case BPF_LD|BPF_W|BPF_LEN:
175*8b26181fSAndroid Build Coastguard Worker op = "ld";
176*8b26181fSAndroid Build Coastguard Worker operand = "#pktlen";
177*8b26181fSAndroid Build Coastguard Worker break;
178*8b26181fSAndroid Build Coastguard Worker
179*8b26181fSAndroid Build Coastguard Worker case BPF_LD|BPF_W|BPF_IND:
180*8b26181fSAndroid Build Coastguard Worker op = "ld";
181*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "[x + %d]", p->k);
182*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
183*8b26181fSAndroid Build Coastguard Worker break;
184*8b26181fSAndroid Build Coastguard Worker
185*8b26181fSAndroid Build Coastguard Worker case BPF_LD|BPF_H|BPF_IND:
186*8b26181fSAndroid Build Coastguard Worker op = "ldh";
187*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "[x + %d]", p->k);
188*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
189*8b26181fSAndroid Build Coastguard Worker break;
190*8b26181fSAndroid Build Coastguard Worker
191*8b26181fSAndroid Build Coastguard Worker case BPF_LD|BPF_B|BPF_IND:
192*8b26181fSAndroid Build Coastguard Worker op = "ldb";
193*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "[x + %d]", p->k);
194*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
195*8b26181fSAndroid Build Coastguard Worker break;
196*8b26181fSAndroid Build Coastguard Worker
197*8b26181fSAndroid Build Coastguard Worker case BPF_LD|BPF_IMM:
198*8b26181fSAndroid Build Coastguard Worker op = "ld";
199*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#0x%x", p->k);
200*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
201*8b26181fSAndroid Build Coastguard Worker break;
202*8b26181fSAndroid Build Coastguard Worker
203*8b26181fSAndroid Build Coastguard Worker case BPF_LDX|BPF_IMM:
204*8b26181fSAndroid Build Coastguard Worker op = "ldx";
205*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#0x%x", p->k);
206*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
207*8b26181fSAndroid Build Coastguard Worker break;
208*8b26181fSAndroid Build Coastguard Worker
209*8b26181fSAndroid Build Coastguard Worker case BPF_LDX|BPF_MSH|BPF_B:
210*8b26181fSAndroid Build Coastguard Worker op = "ldxb";
211*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "4*([%d]&0xf)", p->k);
212*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
213*8b26181fSAndroid Build Coastguard Worker break;
214*8b26181fSAndroid Build Coastguard Worker
215*8b26181fSAndroid Build Coastguard Worker case BPF_LD|BPF_MEM:
216*8b26181fSAndroid Build Coastguard Worker op = "ld";
217*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "M[%d]", p->k);
218*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
219*8b26181fSAndroid Build Coastguard Worker break;
220*8b26181fSAndroid Build Coastguard Worker
221*8b26181fSAndroid Build Coastguard Worker case BPF_LDX|BPF_MEM:
222*8b26181fSAndroid Build Coastguard Worker op = "ldx";
223*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "M[%d]", p->k);
224*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
225*8b26181fSAndroid Build Coastguard Worker break;
226*8b26181fSAndroid Build Coastguard Worker
227*8b26181fSAndroid Build Coastguard Worker case BPF_ST:
228*8b26181fSAndroid Build Coastguard Worker op = "st";
229*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "M[%d]", p->k);
230*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
231*8b26181fSAndroid Build Coastguard Worker break;
232*8b26181fSAndroid Build Coastguard Worker
233*8b26181fSAndroid Build Coastguard Worker case BPF_STX:
234*8b26181fSAndroid Build Coastguard Worker op = "stx";
235*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "M[%d]", p->k);
236*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
237*8b26181fSAndroid Build Coastguard Worker break;
238*8b26181fSAndroid Build Coastguard Worker
239*8b26181fSAndroid Build Coastguard Worker case BPF_JMP|BPF_JA:
240*8b26181fSAndroid Build Coastguard Worker op = "ja";
241*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "%d", n + 1 + p->k);
242*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
243*8b26181fSAndroid Build Coastguard Worker break;
244*8b26181fSAndroid Build Coastguard Worker
245*8b26181fSAndroid Build Coastguard Worker case BPF_JMP|BPF_JGT|BPF_K:
246*8b26181fSAndroid Build Coastguard Worker op = "jgt";
247*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#0x%x", p->k);
248*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
249*8b26181fSAndroid Build Coastguard Worker break;
250*8b26181fSAndroid Build Coastguard Worker
251*8b26181fSAndroid Build Coastguard Worker case BPF_JMP|BPF_JGE|BPF_K:
252*8b26181fSAndroid Build Coastguard Worker op = "jge";
253*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#0x%x", p->k);
254*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
255*8b26181fSAndroid Build Coastguard Worker break;
256*8b26181fSAndroid Build Coastguard Worker
257*8b26181fSAndroid Build Coastguard Worker case BPF_JMP|BPF_JEQ|BPF_K:
258*8b26181fSAndroid Build Coastguard Worker op = "jeq";
259*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#0x%x", p->k);
260*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
261*8b26181fSAndroid Build Coastguard Worker break;
262*8b26181fSAndroid Build Coastguard Worker
263*8b26181fSAndroid Build Coastguard Worker case BPF_JMP|BPF_JSET|BPF_K:
264*8b26181fSAndroid Build Coastguard Worker op = "jset";
265*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#0x%x", p->k);
266*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
267*8b26181fSAndroid Build Coastguard Worker break;
268*8b26181fSAndroid Build Coastguard Worker
269*8b26181fSAndroid Build Coastguard Worker case BPF_JMP|BPF_JGT|BPF_X:
270*8b26181fSAndroid Build Coastguard Worker op = "jgt";
271*8b26181fSAndroid Build Coastguard Worker operand = "x";
272*8b26181fSAndroid Build Coastguard Worker break;
273*8b26181fSAndroid Build Coastguard Worker
274*8b26181fSAndroid Build Coastguard Worker case BPF_JMP|BPF_JGE|BPF_X:
275*8b26181fSAndroid Build Coastguard Worker op = "jge";
276*8b26181fSAndroid Build Coastguard Worker operand = "x";
277*8b26181fSAndroid Build Coastguard Worker break;
278*8b26181fSAndroid Build Coastguard Worker
279*8b26181fSAndroid Build Coastguard Worker case BPF_JMP|BPF_JEQ|BPF_X:
280*8b26181fSAndroid Build Coastguard Worker op = "jeq";
281*8b26181fSAndroid Build Coastguard Worker operand = "x";
282*8b26181fSAndroid Build Coastguard Worker break;
283*8b26181fSAndroid Build Coastguard Worker
284*8b26181fSAndroid Build Coastguard Worker case BPF_JMP|BPF_JSET|BPF_X:
285*8b26181fSAndroid Build Coastguard Worker op = "jset";
286*8b26181fSAndroid Build Coastguard Worker operand = "x";
287*8b26181fSAndroid Build Coastguard Worker break;
288*8b26181fSAndroid Build Coastguard Worker
289*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_ADD|BPF_X:
290*8b26181fSAndroid Build Coastguard Worker op = "add";
291*8b26181fSAndroid Build Coastguard Worker operand = "x";
292*8b26181fSAndroid Build Coastguard Worker break;
293*8b26181fSAndroid Build Coastguard Worker
294*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_SUB|BPF_X:
295*8b26181fSAndroid Build Coastguard Worker op = "sub";
296*8b26181fSAndroid Build Coastguard Worker operand = "x";
297*8b26181fSAndroid Build Coastguard Worker break;
298*8b26181fSAndroid Build Coastguard Worker
299*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_MUL|BPF_X:
300*8b26181fSAndroid Build Coastguard Worker op = "mul";
301*8b26181fSAndroid Build Coastguard Worker operand = "x";
302*8b26181fSAndroid Build Coastguard Worker break;
303*8b26181fSAndroid Build Coastguard Worker
304*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_DIV|BPF_X:
305*8b26181fSAndroid Build Coastguard Worker op = "div";
306*8b26181fSAndroid Build Coastguard Worker operand = "x";
307*8b26181fSAndroid Build Coastguard Worker break;
308*8b26181fSAndroid Build Coastguard Worker
309*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_MOD|BPF_X:
310*8b26181fSAndroid Build Coastguard Worker op = "mod";
311*8b26181fSAndroid Build Coastguard Worker operand = "x";
312*8b26181fSAndroid Build Coastguard Worker break;
313*8b26181fSAndroid Build Coastguard Worker
314*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_AND|BPF_X:
315*8b26181fSAndroid Build Coastguard Worker op = "and";
316*8b26181fSAndroid Build Coastguard Worker operand = "x";
317*8b26181fSAndroid Build Coastguard Worker break;
318*8b26181fSAndroid Build Coastguard Worker
319*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_OR|BPF_X:
320*8b26181fSAndroid Build Coastguard Worker op = "or";
321*8b26181fSAndroid Build Coastguard Worker operand = "x";
322*8b26181fSAndroid Build Coastguard Worker break;
323*8b26181fSAndroid Build Coastguard Worker
324*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_XOR|BPF_X:
325*8b26181fSAndroid Build Coastguard Worker op = "xor";
326*8b26181fSAndroid Build Coastguard Worker operand = "x";
327*8b26181fSAndroid Build Coastguard Worker break;
328*8b26181fSAndroid Build Coastguard Worker
329*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_LSH|BPF_X:
330*8b26181fSAndroid Build Coastguard Worker op = "lsh";
331*8b26181fSAndroid Build Coastguard Worker operand = "x";
332*8b26181fSAndroid Build Coastguard Worker break;
333*8b26181fSAndroid Build Coastguard Worker
334*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_RSH|BPF_X:
335*8b26181fSAndroid Build Coastguard Worker op = "rsh";
336*8b26181fSAndroid Build Coastguard Worker operand = "x";
337*8b26181fSAndroid Build Coastguard Worker break;
338*8b26181fSAndroid Build Coastguard Worker
339*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_ADD|BPF_K:
340*8b26181fSAndroid Build Coastguard Worker op = "add";
341*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#%d", p->k);
342*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
343*8b26181fSAndroid Build Coastguard Worker break;
344*8b26181fSAndroid Build Coastguard Worker
345*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_SUB|BPF_K:
346*8b26181fSAndroid Build Coastguard Worker op = "sub";
347*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#%d", p->k);
348*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
349*8b26181fSAndroid Build Coastguard Worker break;
350*8b26181fSAndroid Build Coastguard Worker
351*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_MUL|BPF_K:
352*8b26181fSAndroid Build Coastguard Worker op = "mul";
353*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#%d", p->k);
354*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
355*8b26181fSAndroid Build Coastguard Worker break;
356*8b26181fSAndroid Build Coastguard Worker
357*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_DIV|BPF_K:
358*8b26181fSAndroid Build Coastguard Worker op = "div";
359*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#%d", p->k);
360*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
361*8b26181fSAndroid Build Coastguard Worker break;
362*8b26181fSAndroid Build Coastguard Worker
363*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_MOD|BPF_K:
364*8b26181fSAndroid Build Coastguard Worker op = "mod";
365*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#%d", p->k);
366*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
367*8b26181fSAndroid Build Coastguard Worker break;
368*8b26181fSAndroid Build Coastguard Worker
369*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_AND|BPF_K:
370*8b26181fSAndroid Build Coastguard Worker op = "and";
371*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#0x%x", p->k);
372*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
373*8b26181fSAndroid Build Coastguard Worker break;
374*8b26181fSAndroid Build Coastguard Worker
375*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_OR|BPF_K:
376*8b26181fSAndroid Build Coastguard Worker op = "or";
377*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#0x%x", p->k);
378*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
379*8b26181fSAndroid Build Coastguard Worker break;
380*8b26181fSAndroid Build Coastguard Worker
381*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_XOR|BPF_K:
382*8b26181fSAndroid Build Coastguard Worker op = "xor";
383*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#0x%x", p->k);
384*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
385*8b26181fSAndroid Build Coastguard Worker break;
386*8b26181fSAndroid Build Coastguard Worker
387*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_LSH|BPF_K:
388*8b26181fSAndroid Build Coastguard Worker op = "lsh";
389*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#%d", p->k);
390*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
391*8b26181fSAndroid Build Coastguard Worker break;
392*8b26181fSAndroid Build Coastguard Worker
393*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_RSH|BPF_K:
394*8b26181fSAndroid Build Coastguard Worker op = "rsh";
395*8b26181fSAndroid Build Coastguard Worker (void)snprintf(operand_buf, sizeof operand_buf, "#%d", p->k);
396*8b26181fSAndroid Build Coastguard Worker operand = operand_buf;
397*8b26181fSAndroid Build Coastguard Worker break;
398*8b26181fSAndroid Build Coastguard Worker
399*8b26181fSAndroid Build Coastguard Worker case BPF_ALU|BPF_NEG:
400*8b26181fSAndroid Build Coastguard Worker op = "neg";
401*8b26181fSAndroid Build Coastguard Worker operand = "";
402*8b26181fSAndroid Build Coastguard Worker break;
403*8b26181fSAndroid Build Coastguard Worker
404*8b26181fSAndroid Build Coastguard Worker case BPF_MISC|BPF_TAX:
405*8b26181fSAndroid Build Coastguard Worker op = "tax";
406*8b26181fSAndroid Build Coastguard Worker operand = "";
407*8b26181fSAndroid Build Coastguard Worker break;
408*8b26181fSAndroid Build Coastguard Worker
409*8b26181fSAndroid Build Coastguard Worker case BPF_MISC|BPF_TXA:
410*8b26181fSAndroid Build Coastguard Worker op = "txa";
411*8b26181fSAndroid Build Coastguard Worker operand = "";
412*8b26181fSAndroid Build Coastguard Worker break;
413*8b26181fSAndroid Build Coastguard Worker }
414*8b26181fSAndroid Build Coastguard Worker if (BPF_CLASS(p->code) == BPF_JMP && BPF_OP(p->code) != BPF_JA) {
415*8b26181fSAndroid Build Coastguard Worker (void)snprintf(image, sizeof image,
416*8b26181fSAndroid Build Coastguard Worker "(%03d) %-8s %-16s jt %d\tjf %d",
417*8b26181fSAndroid Build Coastguard Worker n, op, operand, n + 1 + p->jt, n + 1 + p->jf);
418*8b26181fSAndroid Build Coastguard Worker } else {
419*8b26181fSAndroid Build Coastguard Worker (void)snprintf(image, sizeof image,
420*8b26181fSAndroid Build Coastguard Worker "(%03d) %-8s %s",
421*8b26181fSAndroid Build Coastguard Worker n, op, operand);
422*8b26181fSAndroid Build Coastguard Worker }
423*8b26181fSAndroid Build Coastguard Worker return image;
424*8b26181fSAndroid Build Coastguard Worker }
425