OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [userland/] [route/] [lib/] [inet6_gr.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 745 simons
/*
2
   Modifications:
3
   1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
4
   snprintf instead of sprintf
5
 */
6
 
7
#include "config.h"
8
 
9
#if HAVE_AFINET6
10
#include <asm/types.h>
11
#include <asm/param.h>
12
#include <sys/types.h>
13
#include <sys/socket.h>
14
#include <netinet/in.h>
15
#include <arpa/inet.h>
16
#include <arpa/nameser.h>
17
/* #include <net/route.h> realy broken */
18
#include <ctype.h>
19
#include <errno.h>
20
#include <netdb.h>
21
#include <resolv.h>
22
#include <stdlib.h>
23
#include <string.h>
24
#include <stdio.h>
25
#include <unistd.h>
26
#ifndef __GLIBC__
27
#include <netinet6/ipv6_route.h>        /* glibc doesn't have this */
28
#endif
29
#include "version.h"
30
#include "net-support.h"
31
#include "pathnames.h"
32
#include "intl.h"
33
#include "net-features.h"
34
 
35
/* this is from linux/include/net/ndisc.h */
36
/*
37
 *    Neighbor Cache Entry States (7.3.2.)
38
 */
39
 
40
/*
41
 *    The lsb is set for states that have a timer associated
42
 */
43
 
44
#define NUD_NONE        0x00
45
#define NUD_INCOMPLETE  0x11
46
#define NUD_REACHABLE   0x20
47
#define NUD_STALE       0x30
48
#define NUD_DELAY       0x41
49
#define NUD_PROBE       0x51
50
#define NUD_FAILED      0x60    /* neighbour discovery failed     */
51
 
52
#define NUD_IN_TIMER    0x01
53
 
54
#define NDISC_QUEUE_LEN 3
55
 
56
#define NCF_NOARP               0x0100  /* no ARP needed on this device */
57
#define NCF_SUBNET              0x0200  /* NC entry for subnet            */
58
#define NCF_INVALID             0x0400
59
#define NCF_DELAY_EXPIRED       0x0800  /* time to move to PROBE  */
60
#define NCF_ROUTER              0x1000  /* neighbour is a router  */
61
#define NCF_HHVALID             0x2000  /* Hardware header is valid       */
62
 
63
 
64
extern struct aftype inet6_aftype;
65
 
66
 
67
int rprint_fib6(int ext, int numeric)
68
{
69
    char buff[4096], iface[16], flags[16];
70
    char addr6[128], naddr6[128];
71
    struct sockaddr_in6 saddr6, snaddr6;
72
    int num, iflags, metric, refcnt, use, prefix_len, slen;
73
    FILE *fp = fopen(_PATH_PROCNET_ROUTE6, "r");
74
 
75
    char addr6p[8][5], saddr6p[8][5], naddr6p[8][5];
76
 
77
    if (!fp) {
78
        perror(_PATH_PROCNET_ROUTE6);
79
        printf(_("INET6 (IPv6) not configured in this system.\n"));
80
        return 1;
81
    }
82
    printf(_("Kernel IPv6 routing table\n"));
83
 
84
    printf(_("Destination                                 "
85
             "Next Hop                                "
86
             "Flags Metric Ref    Use Iface\n"));
87
 
88
    while (fgets(buff, 1023, fp)) {
89
        num = sscanf(buff, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %4s%4s%4s%4s%4s%4s%4s%4s %02x %4s%4s%4s%4s%4s%4s%4s%4s %08x %08x %08x %08x %s\n",
90
                     addr6p[0], addr6p[1], addr6p[2], addr6p[3],
91
                     addr6p[4], addr6p[5], addr6p[6], addr6p[7],
92
                     &prefix_len,
93
                     saddr6p[0], saddr6p[1], saddr6p[2], saddr6p[3],
94
                     saddr6p[4], saddr6p[5], saddr6p[6], saddr6p[7],
95
                     &slen,
96
                     naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3],
97
                     naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7],
98
                     &metric, &use, &refcnt, &iflags, iface);
99
#if 0
100
        if (num < 23)
101
            continue;
102
#endif
103
        if (!(iflags & RTF_UP))
104
            continue;
105
        /* Fetch and resolve the target address. */
106
        snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
107
                 addr6p[0], addr6p[1], addr6p[2], addr6p[3],
108
                 addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
109
        inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6);
110
        snprintf(addr6, sizeof(addr6), "%s/%d",
111
                 inet6_aftype.sprint((struct sockaddr *) &saddr6, 1),
112
                 prefix_len);
113
 
114
        /* Fetch and resolve the nexthop address. */
115
        snprintf(naddr6, sizeof(naddr6), "%s:%s:%s:%s:%s:%s:%s:%s",
116
                 naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3],
117
                 naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7]);
118
        inet6_aftype.input(1, naddr6, (struct sockaddr *) &snaddr6);
119
        snprintf(naddr6, sizeof(naddr6), "%s",
120
                 inet6_aftype.sprint((struct sockaddr *) &snaddr6, 1));
121
 
122
        /* Decode the flags. */
123
        strcpy(flags, "U");
124
        if (iflags & RTF_GATEWAY)
125
            strcat(flags, "G");
126
        if (iflags & RTF_HOST)
127
            strcat(flags, "H");
128
        if (iflags & RTF_DEFAULT)
129
            strcat(flags, "D");
130
        if (iflags & RTF_ADDRCONF)
131
            strcat(flags, "A");
132
        if (iflags & RTF_CACHE)
133
            strcat(flags, "C");
134
 
135
        /* Print the info. */
136
        printf("%-43s %-39s %-5s %-6d %-2d %7d %-8s\n",
137
               addr6, naddr6, flags, metric, refcnt, use, iface);
138
    }
139
 
140
    (void) fclose(fp);
141
    return (0);
142
}
143
 
144
int rprint_cache6(int ext, int numeric)
145
{
146
    char buff[4096], iface[16], flags[16];
147
    char addr6[128], haddr[20], statestr[20];
148
    struct sockaddr_in6 saddr6;
149
    int type, num, refcnt, prefix_len, location, state, gc;
150
    long tstamp, expire, ndflags, reachable, stale, delete;
151
    FILE *fp = fopen(_PATH_PROCNET_NDISC, "r");
152
    char addr6p[8][5], haddrp[6][3];
153
 
154
    if (!fp) {
155
        ESYSNOT("nd_print", "ND Table");
156
        return 1;
157
    }
158
    printf(_("Kernel IPv6 Neighbour Cache\n"));
159
 
160
    if (ext == 2)
161
        printf(_("Neighbour                                   "
162
                 "HW Address        "
163
                 "Iface    Flags Ref State\n"));
164
    else
165
        printf(_("Neighbour                                   "
166
                 "HW Address        "
167
        "Iface    Flags Ref State            Stale(sec) Delete(sec)\n"));
168
 
169
 
170
    while (fgets(buff, 1023, fp)) {
171
        num = sscanf(buff, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %08lx %08lx %08lx %04x %04x %04lx %8s %2s%2s%2s%2s%2s%2s\n",
172
                     addr6p[0], addr6p[1], addr6p[2], addr6p[3],
173
                     addr6p[4], addr6p[5], addr6p[6], addr6p[7],
174
                     &location, &prefix_len, &type, &state, &expire, &tstamp, &reachable, &gc, &refcnt,
175
                     &ndflags, iface,
176
        haddrp[0], haddrp[1], haddrp[2], haddrp[3], haddrp[4], haddrp[5]);
177
 
178
        /* Fetch and resolve the nexthop address. */
179
        snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
180
                 addr6p[0], addr6p[1], addr6p[2], addr6p[3],
181
                 addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
182
        inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6);
183
        snprintf(addr6, sizeof(addr6), "%s/%d",
184
               inet6_aftype.sprint((struct sockaddr *) &saddr6, numeric),
185
                 prefix_len);
186
 
187
        /* Fetch the  hardware address. */
188
        snprintf(haddr, sizeof(haddr), "%s:%s:%s:%s:%s:%s",
189
        haddrp[0], haddrp[1], haddrp[2], haddrp[3], haddrp[4], haddrp[5]);
190
 
191
        /* Decode the flags. */
192
        flags[0] = '\0';
193
        if (ndflags & NCF_NOARP)
194
            strcat(flags, "N");
195
        if (ndflags & NCF_SUBNET)
196
            strcat(flags, "S");
197
        if (ndflags & NCF_INVALID)
198
            strcat(flags, "I");
199
        if (ndflags & NCF_DELAY_EXPIRED)
200
            strcat(flags, "D");
201
        if (ndflags & NCF_ROUTER)
202
            strcat(flags, "R");
203
        if (ndflags & NCF_HHVALID)
204
            strcat(flags, "H");
205
 
206
        /* Decode the state */
207
        switch (state) {
208
        case NUD_NONE:
209
            strcpy(statestr, "NONE");
210
            break;
211
        case NUD_INCOMPLETE:
212
            strcpy(statestr, "INCOMPLETE");
213
            break;
214
        case NUD_REACHABLE:
215
            strcpy(statestr, "REACHABLE");
216
            break;
217
        case NUD_STALE:
218
            strcpy(statestr, "STALE");
219
            break;
220
        case NUD_DELAY:
221
            strcpy(statestr, "DELAY");
222
            break;
223
        case NUD_PROBE:
224
            strcpy(statestr, "PROBE");
225
            break;
226
        case NUD_FAILED:
227
            strcpy(statestr, "FAILED");
228
            break;
229
        case NUD_IN_TIMER:
230
            strcpy(statestr, "IN TIMER");
231
            break;
232
        default:
233
            snprintf(statestr, sizeof(statestr), "UNKNOWN %02x", state);
234
            break;
235
        }
236
 
237
        /* Print the info. */
238
        printf("%-43s %-17s %-8s %-5s %-3d %-16s",
239
               addr6, haddr, iface, flags, refcnt, statestr);
240
 
241
        stale = 0;
242
        if (state == NUD_REACHABLE)
243
            stale = reachable > tstamp ? reachable - tstamp : 0;
244
        delete = gc > tstamp ? gc - tstamp : 0;
245
        if (ext != 2) {
246
            printf(" %-9ld ", stale / HZ);
247
            if (refcnt)
248
                printf(" * ");
249
            else
250
                printf(" %-7ld ", delete / HZ);
251
        }
252
        printf("\n");
253
    }
254
 
255
    (void) fclose(fp);
256
    return (0);
257
}
258
 
259
int INET6_rprint(int options)
260
{
261
    int ext = options & FLAG_EXT;
262
    int numeric = options & (FLAG_NUM | FLAG_SYM);
263
    int rc = E_INTERN;
264
 
265
    if (options & FLAG_FIB)
266
        if ((rc = rprint_fib6(ext, numeric)))
267
            return (rc);
268
 
269
    if (options & FLAG_CACHE)
270
        if ((rc = rprint_cache6(ext, numeric)))
271
            return (rc);
272
    return (rc);
273
}
274
 
275
#endif                          /* HAVE_AFINET6 */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.