1: /* pathalias -- by steve bellovin, as told to peter honeyman */
2:
3: #ifndef lint
4: #ifdef MAIN
5: static char *h_sccsid = "@(#)def.h 9.1 87/10/04";
6: #endif /*MAIN*/
7: #endif /*lint*/
8:
9: #include <stdio.h>
10: #include <ctype.h>
11: #include "config.h"
12: #ifdef TMPFILES
13: #include <sys/types.h>
14: #include <sys/file.h>
15: #endif /*TMPFILES*/
16:
17: typedef long Cost;
18: typedef struct node node;
19: typedef struct link link;
20:
21: #ifndef TMPFILES
22: #define p_node node *
23: #define p_link link *
24: #else /*TMPFILES*/
25: #define p_node unsigned int
26: #define p_link unsigned int
27: #endif /*TMPFILES*/
28:
29: #ifdef lint
30: #define vprintf fprintf
31: #else /*!lint -- this gives null effect warning*/
32: /* because it's there ... */
33: #define vprintf !Vflag ? 0 : fprintf
34: #endif /*lint*/
35:
36: #define NTRACE 16 /* can trace up to NTRACE hosts/links */
37: #ifdef TMPFILES
38: #define MAXNAME 127 /* Maximum length of node name. */
39: #endif /*TMPFILES*/
40:
41:
42: /* scanner states (yylex, parse) */
43: #define OTHER 0
44: #define COSTING 1
45: #define NEWLINE 2
46:
47: /* flags for n_flag */
48: #define ISPRIVATE 0x0001 /* invisible outside its definition file */
49: #define NALIAS 0x0002 /* heaped as an alias */
50: #define ATSIGN 0x0004 /* seen an at sign? used for magic @/% rules */
51: #define MAPPED 0x0008 /* extracted from heap */
52: #define NDEAD 0x0010 /* out links are dead */
53: #define HASLEFT 0x0020 /* has a left side net character */
54: #define HASRIGHT 0x0040 /* route has a right side net character */
55: #define NNET 0x0080 /* network pseudo-host */
56: #define INDFS 0x0100 /* used when removing net cycles (for -g) */
57: #define DUMP 0x0200 /* we have dumped this net's edges (for -g) */
58: #define PRINTED 0x0400 /* this host has been printed */
59: #define NTERMINAL 0x0800 /* heaped as terminal edge (or alias thereto) */
60:
61: #define ISADOMAIN(n) ((n)->n_name[0] == '.')
62: #define ISANET(n) (((n)->n_flag & NNET) || ISADOMAIN(n))
63: #define DEADHOST(n) ((((n)->n_flag & (NNET | NDEAD)) == NDEAD) || (n->n_flag & NTERMINAL))
64: #define GATEWAYED(n) (((n)->n_flag & (NNET | NDEAD)) == (NNET | NDEAD) || ISADOMAIN(n))
65:
66: #ifndef DEBUG
67: /*
68: * save some space in nodes -- there are > 10,000 allocated!
69: */
70:
71: #define n_root un1.nu_root
72: #define n_net un1.nu_net
73: #define n_copy un1.nu_copy
74:
75: #define n_private un2.nu_priv
76: #define n_parent un2.nu_par
77:
78: /* WARNING: if > 2^16 nodes, type of n_tloc must change */
79: struct node {
80: char *n_name; /* host name */
81: #ifdef TMPFILES
82: off_t n_fname; /* offset to name in name temp file */
83: p_node n_seq; /* sequence number of node */
84: #endif /*TMPFILES*/
85: p_link n_link; /* adjacency list */
86: Cost n_cost; /* cost to this host */
87: union {
88: p_node nu_net; /* others in this network (parsing) */
89: p_node nu_root; /* root of net cycle (graph dumping) */
90: p_node nu_copy; /* circular copy list (mapping) */
91: } un1;
92: union {
93: p_node nu_priv; /* other privates in this file (parsing) */
94: p_node nu_par; /* parent in shortest path tree (mapping) */
95: } un2;
96: unsigned short n_tloc; /* back ptr to heap/hash table */
97: unsigned short n_flag; /* see manifests above */
98: };
99:
100: #endif /*DEBUG*/
101:
102: #define DEFNET '!' /* default network operator */
103: #define DEFDIR LLEFT /* host on left is default */
104: #define DEFCOST ((Cost) 4000) /* default cost of a link */
105: #define INF ((Cost) 30000000) /* infinitely expensive link */
106: #define DEFPENALTY ((Cost) 200) /* default avoidance cost */
107:
108: /* data structure for adjacency list representation */
109:
110: /* flags for l_dir */
111:
112: #define NETDIR(l) ((l)->l_flag & LDIR)
113: #define NETCHAR(l) ((l)->l_netop)
114:
115: #define LDIR 0x0008 /* 0 for left, 1 for right */
116: #define LRIGHT 0x0000 /* user@host style */
117: #define LLEFT 0x0008 /* host!user style */
118:
119: #define LDEAD 0x0010 /* this link is dead */
120: #define LALIAS 0x0020 /* this link is an alias */
121: #define LTREE 0x0040 /* member of shortest path tree */
122: #define LGATEWAY 0x0080 /* this link is a gateway */
123: #define LTERMINAL 0x0100 /* this link is terminal */
124:
125: #ifndef DEBUG
126: /*
127: * borrow a field for link/node tracing. there's a shitload of
128: * edges -- every word counts. only so much squishing is possible:
129: * alignment dictates that the size be a multiple of four.
130: */
131:
132: #define l_next un.lu_next
133: #define l_from un.lu_from
134:
135: struct link {
136: p_node l_to; /* adjacent node */
137: #ifdef TMPFILES
138: p_link l_seq; /* link sequence number */
139: #endif /*TMPFILES*/
140: Cost l_cost; /* edge cost */
141: union {
142: p_link lu_next; /* rest of adjacency list (not tracing) */
143: p_node lu_from; /* source node (tracing) */
144: } un;
145: short l_flag; /* right/left syntax, flags */
146: char l_netop; /* network operator */
147: };
148:
149: #endif /*DEBUG*/
150:
151: #ifdef DEBUG
152: /*
153: * flattening out the unions makes it easier
154: * to debug (when pi is unavailable).
155: */
156: struct node {
157: char *n_name;
158: #ifdef TMPFILES
159: off_t n_fname;
160: p_node n_seq;
161: #endif /*TMPFILES*/
162: p_link n_link;
163: Cost n_cost;
164: p_node n_net;
165: p_node n_root;
166: p_node n_copy;
167: p_node n_private;
168: p_node n_parent;
169: unsigned short n_tloc;
170: unsigned short n_flag;
171: };
172: struct link {
173: p_node l_to;
174: #ifdef TMPFILES
175: p_link l_seq;
176: #endif /*TMPFILES*/
177: Cost l_cost;
178: p_link l_next;
179: p_node l_from;
180: short l_flag;
181: char l_netop;
182: };
183: #endif /*DEBUG*/
Defined variables
Defined struct's
link
defined in line
172; used 3 times
node
defined in line
156; used 3 times
Defined typedef's
Cost
defined in line
17; used 30 times
- in line 86,
104-106(3),
140,
163,
177
- in /usr/src/new/pathalias/addlink.c line
39,
178,
204
- in /usr/src/new/pathalias/addnode.c line
107-109(2),
395
- in /usr/src/new/pathalias/mapaux.c line
71-76(2)
- in /usr/src/new/pathalias/mapit.c line
48,
133,
227,
279-284(2),
360
- in /usr/src/new/pathalias/parse.y line
40-45(2),
221,
232,
251,
279
- in /usr/src/new/pathalias/printit.c line
73,
281,
300
link
defined in line
19; used 34 times
- in line 23
- in /usr/src/new/pathalias/addlink.c line
26
- in /usr/src/new/pathalias/addnode.c line
24
- in /usr/src/new/pathalias/getstruct.c line
32,
42-47(2),
226,
234,
241,
252-255(2),
263-264(2),
271-274(2),
283-286(3),
298-302(3)
- in /usr/src/new/pathalias/main.c line
38
- in /usr/src/new/pathalias/mapaux.c line
22
- in /usr/src/new/pathalias/mapit.c line
27
- in /usr/src/new/pathalias/mem.c line
22-26(2),
33-39(4),
56-58(2)
- in /usr/src/new/pathalias/parse.y line
22
- in /usr/src/new/pathalias/printit.c line
24
node
defined in line
18; used 34 times
- in line 22
- in /usr/src/new/pathalias/addlink.c line
25
- in /usr/src/new/pathalias/addnode.c line
23
- in /usr/src/new/pathalias/getstruct.c line
26,
41-46(2),
115,
123,
130,
141-144(2),
153-156(4),
163-166(2),
177,
186-187(2),
200-204(3)
- in /usr/src/new/pathalias/main.c line
37
- in /usr/src/new/pathalias/mapaux.c line
21
- in /usr/src/new/pathalias/mapit.c line
26
- in /usr/src/new/pathalias/mem.c line
21,
85-87(3),
105-107(2)
- in /usr/src/new/pathalias/parse.y line
21
- in /usr/src/new/pathalias/printit.c line
23
Defined macros
DUMP
defined in line
57;
never used
INDFS
defined in line
56; used 3 times
INF
defined in line
105; used 10 times
LDIR
defined in line
115; used 4 times
MAPPED
defined in line
51; used 10 times
NDEAD
defined in line
52; used 5 times
NNET
defined in line
55; used 13 times
OTHER
defined in line
43; used 2 times
l_next
defined in line
132; used 36 times
- in line 178
- in /usr/src/new/pathalias/addlink.c line
49,
68-71(4),
108-119(9),
132
- in /usr/src/new/pathalias/mapaux.c line
117,
138,
145,
158,
200,
228,
368(2),
376-377(2)
- in /usr/src/new/pathalias/mapit.c line
135,
527,
634,
644
- in /usr/src/new/pathalias/mem.c line
37,
75
- in /usr/src/new/pathalias/printit.c line
52,
101,
145,
154
n_copy
defined in line
73; used 16 times
n_net
defined in line
72; used 5 times
n_parent
defined in line
76; used 32 times
- in line 168
- in /usr/src/new/pathalias/mapaux.c line
257,
266-269(4),
317
- in /usr/src/new/pathalias/mapit.c line
89,
172-176(3),
209,
257,
538,
548,
565,
599-603(4)
- in /usr/src/new/pathalias/printit.c line
137,
146,
155,
177,
192,
244,
252,
271,
314,
322-323(2),
335
n_root
defined in line
71; used 11 times
p_link
defined in line
26; used 78 times
- in line 85,
138-142(2),
162,
175-178(2)
- in /usr/src/new/pathalias/addlink.c line
9,
19,
32-35(2),
41-42(2),
92-95(4),
142,
154,
180,
226,
247
- in /usr/src/new/pathalias/addnode.c line
16,
100
- in /usr/src/new/pathalias/getstruct.c line
228,
299
- in /usr/src/new/pathalias/mapaux.c line
15,
36,
112-115(4),
195,
216,
328,
348-352(4)
- in /usr/src/new/pathalias/mapit.c line
34-35(2),
42-46(2),
54-55(2),
61,
130,
225-230(2),
282,
325,
358,
389-393(4),
423-425(2),
476-477(2),
506,
560,
585,
629,
638
- in /usr/src/new/pathalias/mem.c line
31,
44-47(2),
72
- in /usr/src/new/pathalias/parse.y line
16,
76,
85,
225
- in /usr/src/new/pathalias/printit.c line
30,
43,
69,
118,
170,
240
p_node
defined in line
25; used 139 times
- in line 83-94(6),
136,
143,
160-173(7),
179
- in /usr/src/new/pathalias/addlink.c line
20,
37-38(2),
90-91(2),
155,
176-177(2),
187-191(4),
202-203(2),
224-225(2),
233-234(2),
245-246(2)
- in /usr/src/new/pathalias/addnode.c line
9-18(5),
28,
37-38(2),
61-65(2),
97-98(2),
184,
229-230(2),
344-347(2),
357-358(2),
378,
396
- in /usr/src/new/pathalias/getstruct.c line
117,
201
- in /usr/src/new/pathalias/main.c line
16,
31,
78
- in /usr/src/new/pathalias/mapaux.c line
10-16(3),
30,
67,
84,
110-111(2),
181,
194-196(2),
217,
251-254(3),
312,
324-327(3)
- in /usr/src/new/pathalias/mapit.c line
20-21(2),
37,
53,
129-131(2),
204-206(3),
226-229(2),
281-283(2),
326,
361-362(2),
426-428(3),
490,
507-510(4),
561-562(2),
584-587(2),
639
- in /usr/src/new/pathalias/mem.c line
82,
93-96(2),
140-145(4),
152-156(2)
- in /usr/src/new/pathalias/parse.y line
13-14(2),
39-44(2),
153,
219-224(4)
- in /usr/src/new/pathalias/printit.c line
18,
71-72(2),
116-117(2),
172-173(2),
242,
279,
298-301(2)
Usage of this include