-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrouter.c
233 lines (211 loc) · 6.37 KB
/
router.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
/*
#include <netax25/kernel_ax25.h>
#include <netax25/kernel_rose.h>
*/
#include <netax25/axlib.h>
#include <netax25/axconfig.h>
#include "procinfo.h"
#include "node.h"
int do_links(int argc, char **argv)
{
struct ax_routes *axrt, *p;
char digipath[AX25_MAX_DIGIS*10];
char tipoconn[9];
int i=0;
axio_puts("",NodeIo);
if (User.ul_type == AF_NETROM) {
axio_printf(NodeIo,"%s} ", NodeId);
}
if ((axrt=read_ax_routes()) == NULL) {
if (errno) node_perror("do_links: read_ax_routes", errno);
else axio_printf(NodeIo,"No known links");
if (User.ul_type == AF_NETROM) {
node_msg("");
}
return 0;
}
/* "links" */
if (check_perms(PERM_ANSI, 0L) != -1) {
axio_printf(NodeIo, "\e[01;33m");
}
if (argc == 1) {
node_msg("AX25 Links:");
if (check_perms(PERM_ANSI, 0L) != -1) {
axio_printf(NodeIo, "\e[0;m");
}
axio_printf(NodeIo,"Call Alias Description\n");
axio_printf(NodeIo,"--------- --------- -----------");
for(p=axrt;p!=NULL;p=p->next)
axio_printf(NodeIo,"\n%-9s %-9s %s", p->dest_call, p->alias, p->description);
free_ax_routes(axrt);
if (User.ul_type == AF_NETROM) {
node_msg("");
}
return 0;
}
/* "links d" */
if ((*argv[1]=='d') && (strlen(argv[1])==1)) {
node_msg("AX25 Direct Links:");
axio_printf(NodeIo,"Call Alias Interf Description\n");
axio_printf(NodeIo,"--------- --------- ------- -----------");
for(p=axrt;p!=NULL;p=p->next)
{ if (*p->conn_type==CONN_TYPE_DIRECT) axio_printf(NodeIo,"\n%-9s %-9s %-7s %s", p->dest_call, p->alias, p->dev, p->description); }
free_ax_routes(axrt);
if (User.ul_type == AF_NETROM) {
node_msg("");
}
return 0;
}
/* "links n" */
if ((*argv[1]=='n') && (strlen(argv[1])==1)) {
node_msg("AX25 Links via other nodes:");
axio_printf(NodeIo,"Call Alias Interf Routing Description\n");
axio_printf(NodeIo,"--------- --------- ------- --------- -----------");
for(p=axrt;p!=NULL;p=p->next)
{ if (*p->conn_type==CONN_TYPE_NODE) axio_printf(NodeIo,"\n%-9s %-9s %-7s %-9s %s", p->dest_call, p->alias, p->dev, p->digis[0], p->description); }
free_ax_routes(axrt);
if (User.ul_type == AF_NETROM) {
node_msg("");
}
return 0;
}
/* "links v" */
if ((*argv[1]=='v') && (strlen(argv[1])==1)) {
node_msg("AX25 Links via digipeaters:");
axio_printf(NodeIo,"Call Alias Interf Digipeaters\n");
axio_printf(NodeIo,"--------- --------- ------- -----------");
for(p=axrt;p!=NULL;p=p->next) {
*digipath='\0';
for(i=0;i<AX25_MAX_DIGIS;i++) {
if (p->digis[i]==NULL) break;
if (i!=0) strcat(digipath," ");
strcat(digipath, p->digis[i]);
}
if (*p->conn_type==CONN_TYPE_DIGI) axio_printf(NodeIo,"\n%-9s %-9s %-7s %s", p->dest_call, p->alias, p->dev, digipath);
}
free_ax_routes(axrt);
if (User.ul_type == AF_NETROM) {
node_msg("");
}
return 0;
}
/* "links <call>" */
p=find_route(argv[1], axrt);
if(p!=NULL) {
node_msg("AX25 Link to %s:", p->dest_call);
axio_printf(NodeIo,"Call Alias Interf Type Description\n");
axio_printf(NodeIo,"--------- --------- ------- -------- -----------");
switch(*p->conn_type) {
case CONN_TYPE_DIRECT:
{ strcpy(tipoconn,"Direct"); break; }
case CONN_TYPE_NODE:
{ strcpy(tipoconn,"Via Node"); break; }
case CONN_TYPE_DIGI:
{ strcpy(tipoconn,"Via Digi"); break; }
}
axio_printf(NodeIo,"\n%-9s %-9s %-7s %-8s %s", p->dest_call, p->alias, p->dev, tipoconn, p->description);
if (User.ul_type == AF_NETROM) {
node_msg("");
}
} else {
axio_printf(NodeIo,"No such link");
if (User.ul_type == AF_NETROM) {
node_msg("");
}
}
free_ax_routes(axrt);
return 0;
}
int do_dest(int argc, char **argv)
{
struct flex_dst *fdst, *p;
struct flex_gt *flgt, *q;
char ssid[5];
int i=0;
axio_puts("",NodeIo);
if (User.ul_type == AF_NETROM) {
axio_printf(NodeIo,"%s} ", NodeId);
}
if ((fdst=read_flex_dst()) == NULL) {
axio_printf(NodeIo,"No known destinations");
if (User.ul_type == AF_NETROM) {
node_msg("");
}
return 0;
}
/* "dest" */
if (argc == 1) {
if (check_perms(PERM_ANSI, 0L) != -1) {
axio_printf(NodeIo,"\e[01;33m");
}
axio_printf(NodeIo,"FlexNet Destinations:\n");
if (check_perms(PERM_ANSI, 0L) != -1) {
axio_printf(NodeIo, "\e[0;m");
}
for (p=fdst;p!=NULL;p=p->next) {
sprintf(ssid, "%d-%d", p->ssida, p->sside);
axio_printf(NodeIo,"%-7s %-5s %4ld%s",p->dest_call,ssid,p->rtt,(++i % 4) ? " " : "\n");
}
if ((i % 4) != 0) axio_printf(NodeIo,"");
free_flex_dst(fdst);
if (User.ul_type == AF_NETROM) {
node_msg("");
}
return 0;
}
if ((flgt=read_flex_gt()) == NULL) {
node_perror("do_dest: read_flex_gt", errno);
if (User.ul_type == AF_NETROM) {
node_msg("");
}
return 0;
}
/* "dest *" */
if (*argv[1]=='*') {
node_msg("FlexNet Destinations:");
axio_printf(NodeIo,"Dest SSID RTT Gateway\n");
axio_printf(NodeIo,"-------- ----- ----- --------");
for(p=fdst;p!=NULL;p=p->next) {
sprintf(ssid, "%d-%d", p->ssida, p->sside);
q=find_gateway(p->addr,flgt);
axio_printf(NodeIo,"\n%-8s %-5s %5ld %-8s", p->dest_call, ssid, p->rtt, q!=NULL?q->call:"?");
}
free_flex_dst(fdst);
free_flex_gt(flgt);
if (User.ul_type == AF_NETROM) {
node_msg("");
}
return 0;
}
/* "dest <call>" */
p=find_dest(argv[1], fdst);
if(p!=NULL) {
node_msg("FlexNet Destination %s:", p->dest_call);
axio_printf(NodeIo,"Dest SSID RTT Gateway\n");
axio_printf(NodeIo,"-------- ----- ----- -------");
sprintf(ssid, "%d-%d", p->ssida, p->sside);
q=find_gateway(p->addr,flgt);
axio_printf(NodeIo,"\n%-8s %-5s %5ld %-8s", p->dest_call, ssid, p->rtt, q!=NULL?q->call:"?");
if (User.ul_type == AF_NETROM) {
node_msg("");
}
} else {
axio_printf(NodeIo,"No such destination");
if (User.ul_type == AF_NETROM) {
node_msg("");
}
}
free_flex_dst(fdst);
free_flex_gt(flgt);
return 0;
}