1996-12-13 11:25:54 +03:00
|
|
|
/* $NetBSD: gencode.h,v 1.4 1996/12/13 08:26:04 mikel Exp $ */
|
1995-03-06 14:37:58 +03:00
|
|
|
|
1995-03-06 14:32:59 +03:00
|
|
|
/*
|
1996-12-13 11:25:54 +03:00
|
|
|
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
|
1995-03-06 14:32:59 +03:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that: (1) source code distributions
|
|
|
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
|
|
|
* distributions including binary code include the above copyright notice and
|
|
|
|
* this paragraph in its entirety in the documentation or other materials
|
|
|
|
* provided with the distribution, and (3) all advertising materials mentioning
|
|
|
|
* features or use of this software display the following acknowledgement:
|
|
|
|
* ``This product includes software developed by the University of California,
|
|
|
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
|
|
|
* the University nor the names of its contributors may be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
1996-12-13 11:25:54 +03:00
|
|
|
* @(#) Header: gencode.h,v 1.36 96/07/17 00:11:34 leres Exp (LBL)
|
1995-03-06 14:32:59 +03:00
|
|
|
*/
|
|
|
|
|
1996-12-13 11:25:54 +03:00
|
|
|
/*XXX*/
|
|
|
|
#include "gnuc.h"
|
1995-03-06 14:32:59 +03:00
|
|
|
|
1996-12-13 11:25:54 +03:00
|
|
|
/* Address qualifiers. */
|
1995-03-06 14:32:59 +03:00
|
|
|
|
|
|
|
#define Q_HOST 1
|
|
|
|
#define Q_NET 2
|
|
|
|
#define Q_PORT 3
|
|
|
|
#define Q_GATEWAY 4
|
|
|
|
#define Q_PROTO 5
|
|
|
|
|
|
|
|
/* Protocol qualifiers. */
|
|
|
|
|
|
|
|
#define Q_LINK 1
|
|
|
|
#define Q_IP 2
|
|
|
|
#define Q_ARP 3
|
|
|
|
#define Q_RARP 4
|
|
|
|
#define Q_TCP 5
|
|
|
|
#define Q_UDP 6
|
|
|
|
#define Q_ICMP 7
|
1996-12-13 11:25:54 +03:00
|
|
|
#define Q_IGMP 8
|
|
|
|
#define Q_IGRP 9
|
|
|
|
|
1995-03-06 14:32:59 +03:00
|
|
|
|
1996-12-13 11:25:54 +03:00
|
|
|
#define Q_ATALK 10
|
|
|
|
#define Q_DECNET 11
|
|
|
|
#define Q_LAT 12
|
|
|
|
#define Q_SCA 13
|
|
|
|
#define Q_MOPRC 14
|
|
|
|
#define Q_MOPDL 15
|
1995-03-06 14:32:59 +03:00
|
|
|
|
1996-12-13 11:25:54 +03:00
|
|
|
/* Directional qualifiers. */
|
1995-03-06 14:32:59 +03:00
|
|
|
|
|
|
|
#define Q_SRC 1
|
|
|
|
#define Q_DST 2
|
|
|
|
#define Q_OR 3
|
|
|
|
#define Q_AND 4
|
|
|
|
|
|
|
|
#define Q_DEFAULT 0
|
|
|
|
#define Q_UNDEF 255
|
|
|
|
|
|
|
|
struct stmt {
|
|
|
|
int code;
|
1996-12-13 11:25:54 +03:00
|
|
|
bpf_int32 k;
|
1995-03-06 14:32:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct slist {
|
|
|
|
struct stmt s;
|
|
|
|
struct slist *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A bit vector to represent definition sets. We assume TOT_REGISTERS
|
|
|
|
* is smaller than 8*sizeof(atomset).
|
|
|
|
*/
|
1996-12-13 11:25:54 +03:00
|
|
|
typedef bpf_u_int32 atomset;
|
1995-03-06 14:32:59 +03:00
|
|
|
#define ATOMMASK(n) (1 << (n))
|
|
|
|
#define ATOMELEM(d, n) (d & ATOMMASK(n))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An unbounded set.
|
|
|
|
*/
|
1996-12-13 11:25:54 +03:00
|
|
|
typedef bpf_u_int32 *uset;
|
1995-03-06 14:32:59 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Total number of atomic entities, including accumulator (A) and index (X).
|
|
|
|
* We treat all these guys similarly during flow analysis.
|
|
|
|
*/
|
|
|
|
#define N_ATOMS (BPF_MEMWORDS+2)
|
|
|
|
|
|
|
|
struct edge {
|
|
|
|
int id;
|
|
|
|
int code;
|
|
|
|
uset edom;
|
|
|
|
struct block *succ;
|
|
|
|
struct block *pred;
|
|
|
|
struct edge *next; /* link list of incoming edges for a node */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct block {
|
|
|
|
int id;
|
|
|
|
struct slist *stmts; /* side effect stmts */
|
|
|
|
struct stmt s; /* branch stmt */
|
|
|
|
int mark;
|
1996-12-13 11:25:54 +03:00
|
|
|
int longjt; /* jt branch requires long jump */
|
|
|
|
int longjf; /* jf branch requires long jump */
|
1995-03-06 14:32:59 +03:00
|
|
|
int level;
|
|
|
|
int offset;
|
|
|
|
int sense;
|
|
|
|
struct edge et;
|
|
|
|
struct edge ef;
|
|
|
|
struct block *head;
|
|
|
|
struct block *link; /* link field used by optimizer */
|
|
|
|
uset dom;
|
|
|
|
uset closure;
|
|
|
|
struct edge *in_edges;
|
|
|
|
atomset def, kill;
|
|
|
|
atomset in_use;
|
|
|
|
atomset out_use;
|
1996-12-13 11:25:54 +03:00
|
|
|
int oval;
|
|
|
|
int val[N_ATOMS];
|
1995-03-06 14:32:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct arth {
|
|
|
|
struct block *b; /* protocol checks */
|
|
|
|
struct slist *s; /* stmt list */
|
|
|
|
int regno; /* virtual register number of result */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct qual {
|
|
|
|
unsigned char addr;
|
|
|
|
unsigned char proto;
|
|
|
|
unsigned char dir;
|
|
|
|
unsigned char pad;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct arth *gen_loadi(int);
|
|
|
|
struct arth *gen_load(int, struct arth *, int);
|
|
|
|
struct arth *gen_loadlen(void);
|
|
|
|
struct arth *gen_neg(struct arth *);
|
|
|
|
struct arth *gen_arth(int, struct arth *, struct arth *);
|
|
|
|
|
|
|
|
void gen_and(struct block *, struct block *);
|
|
|
|
void gen_or(struct block *, struct block *);
|
|
|
|
void gen_not(struct block *);
|
|
|
|
|
1996-12-13 11:25:54 +03:00
|
|
|
struct block *gen_scode(const char *, struct qual);
|
|
|
|
struct block *gen_ecode(const u_char *, struct qual);
|
|
|
|
struct block *gen_mcode(const char *, const char *, int, struct qual);
|
|
|
|
struct block *gen_ncode(const char *, bpf_u_int32, struct qual);
|
1995-03-06 14:32:59 +03:00
|
|
|
struct block *gen_proto_abbrev(int);
|
|
|
|
struct block *gen_relation(int, struct arth *, struct arth *, int);
|
|
|
|
struct block *gen_less(int);
|
|
|
|
struct block *gen_greater(int);
|
|
|
|
struct block *gen_byteop(int, int, int);
|
|
|
|
struct block *gen_broadcast(int);
|
|
|
|
struct block *gen_multicast(int);
|
|
|
|
struct block *gen_inbound(int);
|
|
|
|
|
|
|
|
void bpf_optimize(struct block **);
|
1996-12-13 11:25:54 +03:00
|
|
|
#if __STDC__
|
|
|
|
__dead void bpf_error(const char *, ...)
|
|
|
|
__attribute__((volatile, format (printf, 1, 2)));
|
|
|
|
#endif
|
1995-03-06 14:32:59 +03:00
|
|
|
|
|
|
|
void finish_parse(struct block *);
|
1996-12-13 11:25:54 +03:00
|
|
|
char *sdup(const char *);
|
1995-03-06 14:32:59 +03:00
|
|
|
|
|
|
|
struct bpf_insn *icode_to_fcode(struct block *, int *);
|
|
|
|
int pcap_parse(void);
|
|
|
|
void lex_init(char *);
|
|
|
|
void sappend(struct slist *, struct slist *);
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
#define JT(b) ((b)->et.succ)
|
|
|
|
#define JF(b) ((b)->ef.succ)
|