1: /* pathalias -- by steve bellovin, as told to peter honeyman */
2: #ifndef lint
3: #ifdef MAIN
4: static char *h_sccsid = "@(#)def.h 8.1 (down!honey) 86/01/19";
5: #endif /*MAIN*/
6: #endif /*lint*/
7:
8: #include <stdio.h>
9: #include <ctype.h>
10: #include "config.h"
11:
12: typedef long Cost;
13: typedef struct node node;
14: typedef struct link link;
15:
16: #ifdef lint
17: #define vprintf fprintf
18: #else /*!lint -- this gives null effect warning*/
19: /* because it's there ... */
20: #define vprintf !Vflag ? 0 : fprintf
21: #endif /*lint*/
22:
23: #define NTRACE 16 /* can trace up to NTRACE hosts/links */
24:
25: /* scanner states (yylex, parse) */
26: #define OTHER 0
27: #define COSTING 1
28: #define NEWLINE 2
29:
30: #define isnetc(c) ((c)=='!' || (c)==':' || (c)=='@' || (c)=='%')
31:
32: #define dirbits(c) (c)
33:
34: /* flags for n_flag */
35: #define ISPRIVATE 0x0001 /* this node invisible outside its definition file */
36: #define COLLISION 0x0002 /* collides with a private host name */
37: #define ATSIGN 0x0004 /* seen an at sign? used for magic @/% rules */
38: #define MAPPED 0x0008 /* done mapping this node */
39: #define NDEAD 0x0010 /* node is dead */
40: #define HASLEFT 0x0020 /* route has a left side net character */
41: #define HASRIGHT 0x0040 /* route has a right side net character */
42: #define NNET 0x0080 /* node is a network name */
43: #define INDFS 0x0100 /* used when removing net cycles */
44: #define DUMP 0x0200 /* we have dumped this net's edges */
45: #define GATEWAYIN 0x0400 /* heaped via gatewayed net */
46:
47: #define ISADOMAIN(n) ((n)->n_name[0] == '.')
48: #define ISANET(n) (((n)->n_flag & NNET) || ISADOMAIN(n))
49: #define DEADHOST(n) (((n)->n_flag & (NNET | NDEAD)) == NDEAD)
50: #define GATEWAYED(n) (((n)->n_flag & (NNET | NDEAD)) == (NNET | NDEAD) || ISADOMAIN(n))
51:
52:
53: /*
54: * save some space in nodes -- there are > 10,000 allocated!
55: *
56: * node *n_net others in this network (parsing)
57: * node *n_root root of net cycle (mapping)
58: *
59: * node *n_private other privates in this file (parsing)
60: * char *n_parent parent in shortest path tree (mapping)
61: *
62: */
63:
64: #define n_root n_net_root
65: #define n_net n_net_root
66:
67: #define n_private n_private_parent
68: #define n_parent n_private_parent
69:
70: /* WARNING: if > 2^16 nodes, type of n_tloc must change */
71: struct node {
72: char *n_name; /* host name */
73: link *n_link; /* head of adjacency list */
74: node *n_net_root;
75: node *n_private_parent;
76: Cost n_cost; /* cost to this host */
77: unsigned short n_tloc; /* back ptr to heap/hash table */
78: short n_flag; /* see manifests above */
79: };
80:
81: #define DEFNET '!' /* default network operator */
82: #define DEFDIR LLEFT /* host on left is default */
83: #define DEFCOST ((Cost) 4000) /* default cost of a link */
84: #define INF ((Cost) 30000000) /* infinitely expensive link */
85:
86: /* data structure for adjacency list representation */
87:
88: /* flags for l_dir */
89:
90: /*
91: * there's an ugly dependency between the following manifests and the
92: * variable Netchars = "!:^@%", defined in extern.c. this saves 2
93: * bytes per link (of which there are well over 20k). this does not
94: * mean i'm satsified with bad design.
95: */
96: #define NETDIR(l) ((l)->l_flag & LDIR)
97: #define NETCHAR(l) (Netchars[(l)->l_flag & LNETCHARS])
98:
99: #define LNETCHARS 0x3
100: #define LBANG 0x0
101: #define LCOLON 0x1
102: #define LAT 0x2
103: #define LPERCENT 0x3
104:
105: #define LDIR 0x8 /* 0 for left, 1 for right */
106: #define LRIGHT 0x0 /* user@host style */
107: #define LLEFT 0x8 /* host!user style */
108:
109: #define LDEAD 0x10 /* this link is dead */
110: #define LTREE 0x20 /* member of shortest path tree */
111: #define LALIAS 0x40 /* alias */
112: #define LGATEWAY 0x80 /* this link is a gateway */
113:
114: /*
115: * borrow a field for link/node tracing
116: *
117: * link *l_next; rest of adjacency list (not tracing)
118: * link *l_from; source node (tracing) -- requires a cast
119: *
120: */
121:
122: #define l_next l_next_from
123: #define l_from l_next_from
124:
125: struct link {
126: link *l_next_from;
127: node *l_to; /* adjacent node */
128: Cost l_cost; /* edge cost */
129: char l_flag; /* right/left syntax */
130: };
131:
132: /*
133: * static functions don't show up in prof(1), so ...
134: * someday i'll be done profiling.
135: * yeah, sure, like when hell freezes over.
136: */
137: #define STATIC /*static*/
138:
139: /* external functions */
140: extern node *addnode(), *newnode(), **newtable(), *addprivate();
141: extern link *addlink(), *addgateway(), *newlink();
142: extern char *strsave(), *local();
143: extern void pack();
144:
145: /* external variables */
146: extern char *optarg;
147: extern int optind;
148: extern node *Home;
149: extern char *Cfile;
150: extern char **Ifiles;
151: extern char *ProgName;
152: extern int Lineno;
153: extern node **Table;
154: extern long Tabsize;
155: extern char *Netchars;
156: extern int Vflag;
157: extern int Cflag;
158: extern int Iflag;
159: extern int Tflag;
160: extern int Ncount;
161: extern int Lcount;
162: extern char *Graphout;
163: extern char *Linkout;
164: extern node *Private;
165: extern long Hashpart;
166: extern int Scanstate;
Defined variables
Defined struct's
link
defined in line
125; used 1 times
node
defined in line
71; used 1 times
Defined typedef's
Cost
defined in line
12; used 29 times
- in line 76,
83-84(2),
128
- in /usr/src/new/pathalias/addlink.c line
15,
63,
129,
153
- in /usr/src/new/pathalias/addnode.c line
68-70(2)
- in /usr/src/new/pathalias/mapit.c line
11,
25,
146,
188,
194,
305
- in /usr/src/new/pathalias/parse.y line
14-19(2),
162,
174-176(2),
193-198(2),
327,
360,
370
- in /usr/src/new/pathalias/printit.c line
149,
165,
201
link
defined in line
14; used 46 times
- in line 141-73(2),
126
- in /usr/src/new/pathalias/addlink.c line
8-11(2),
19,
59,
67,
78,
91,
109,
121,
133,
175
- in /usr/src/new/pathalias/addnode.c line
65-66(2)
- in /usr/src/new/pathalias/mapaux.c line
64,
128,
149
- in /usr/src/new/pathalias/mapit.c line
10-15(2),
23-24(2),
30,
144-149(2),
191,
248-253(3),
273,
302,
329-333(3),
378,
406
- in /usr/src/new/pathalias/mem.c line
11-16(4)
- in /usr/src/new/pathalias/parse.y line
166
- in /usr/src/new/pathalias/printit.c line
14,
33,
51,
107
node
defined in line
13; used 74 times
- in line 140,
148-153(2),
164-75(3),
127
- in /usr/src/new/pathalias/addlink.c line
13-14(2),
61-62(2),
128,
140-142(4),
152,
173,
181(2)
- in /usr/src/new/pathalias/addnode.c line
9,
33-38(2),
63,
112,
157,
258-262(2),
272,
292-296(2)
- in /usr/src/new/pathalias/extern.c line
8,
22-24(2)
- in /usr/src/new/pathalias/mapaux.c line
37,
61-63(2),
115,
126-129(2),
150,
182-185(2),
249
- in /usr/src/new/pathalias/mapit.c line
22,
145-148(2),
190-193(2),
251,
275,
306,
390,
407
- in /usr/src/new/pathalias/mem.c line
21-26(4),
55-61(3),
67
- in /usr/src/new/pathalias/parse.y line
13-18(2),
160-165(3)
- in /usr/src/new/pathalias/printit.c line
36,
54,
110,
147,
163-167(2),
199
Defined macros
DUMP
defined in line
44;
never used
INDFS
defined in line
43; used 3 times
INF
defined in line
84; used 10 times
LAT
defined in line
102;
never used
LDIR
defined in line
105; used 2 times
NDEAD
defined in line
39; used 5 times
NNET
defined in line
42; used 17 times
OTHER
defined in line
26; used 2 times
STATIC
defined in line
137; used 16 times
- in /usr/src/new/pathalias/addlink.c line
126,
150
- in /usr/src/new/pathalias/addnode.c line
81,
107,
154,
258
- in /usr/src/new/pathalias/mapit.c line
142,
188,
248,
271,
300,
329
- in /usr/src/new/pathalias/parse.y line
360
- in /usr/src/new/pathalias/printit.c line
145,
161,
197
n_net
defined in line
65; used 4 times
n_parent
defined in line
68; used 17 times
- in /usr/src/new/pathalias/mapaux.c line
188,
201-203(2),
253
- in /usr/src/new/pathalias/mapit.c line
91,
171,
424,
434
- in /usr/src/new/pathalias/printit.c line
63,
112,
120,
139,
174,
185(2),
204,
210
n_root
defined in line
64; used 10 times
Usage of this include