2 * lib/x25_sr.c This file contains an implementation of the "X.25"
3 * route change support functions.
5 * Version: @(#)x25_sr.c 1.00 08/15/98
7 * Author: Stephane Fillod, <sfillod@charybde.gyptis.frmug.org>
10 * This program is free software; you can redistribute it
11 * and/or modify it under the terms of the GNU General
12 * Public License as published by the Free Software
13 * Foundation; either version 2 of the License, or (at
14 * your option) any later version.
19 #include <asm/types.h>
20 #include <sys/param.h>
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <sys/ioctl.h>
24 #include <linux/x25.h>
34 #include "net-support.h"
35 #include "pathnames.h"
38 #include "net-locale.h"
42 #include "net-features.h"
44 extern struct aftype x25_aftype;
49 static int usage(void)
51 fprintf(stderr,"Usage: x25_route [-v] del Target[/mask] [dev] If\n");
52 fprintf(stderr," x25_route [-v] add Target[/mask] [dev] If\n");
57 static int X25_setroute(int action, int options, char **args)
59 struct x25_route_struct rt;
60 struct sockaddr_x25 sx25;
67 strcpy(target, *args++);
69 /* Clean out the x25_route_struct structure. */
70 memset((char *) &rt, 0, sizeof(rt));
73 if ((sigdigits = x25_aftype.input(0, target, (struct sockaddr *)&sx25)) < 0) {
74 x25_aftype.herror(target);
77 rt.sigdigits=sigdigits;
79 /* this works with 2.4 and 2.6 headers struct x25_address vs. typedef */
80 memcpy(&rt.address, &sx25.sx25_addr, sizeof(sx25.sx25_addr));
83 if (!strcmp(*args,"device") || !strcmp(*args,"dev")) {
92 strcpy(rt.device, *args);
95 if (rt.device[0]=='\0')
99 if (rt.sigdigits > 15) {
100 fprintf(stderr, _("route: bogus netmask %d\n"), rt.sigdigits);
104 if (rt.sigdigits > strlen(rt.address.x25_addr)) {
105 fprintf(stderr, _("route: netmask doesn't match route address\n"));
109 /* Create a socket to the X25 kernel. */
110 if ((skfd = socket(AF_X25, SOCK_SEQPACKET, 0)) < 0) {
115 /* Tell the kernel to accept this route. */
116 if (action==RTACTION_DEL) {
117 if (ioctl(skfd, SIOCDELRT, &rt) < 0) {
123 if (ioctl(skfd, SIOCADDRT, &rt) < 0) {
130 /* Close the socket. */
135 int X25_rinput(int action, int options, char **args)
137 if (action == RTACTION_FLUSH) {
138 fprintf(stderr,"Flushing `x25' routing table not supported\n");
141 if (options & FLAG_CACHE) {
142 fprintf(stderr,"Modifying `x25' routing cache not supported\n");
145 if ((*args == NULL) || (action == RTACTION_HELP))
148 return(X25_setroute(action, options, args));
150 #endif /* HAVE_AFX25 */