File: route.c

package info (click to toggle)
diald 0.16.5-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 716 kB
  • ctags: 805
  • sloc: ansic: 5,438; tcl: 510; perl: 479; sh: 284; makefile: 166
file content (112 lines) | stat: -rw-r--r-- 3,361 bytes parent folder | download | duplicates (2)
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
/*
 * route.c - diald routing code.
 *
 * Copyright (c) 1994, 1995, 1996 Eric Schenk.
 * All rights reserved. Please see the file LICENSE which should be
 * distributed with this software for terms of use.
 */

#include "diald.h"

/* set up a point to point route for a device */
void set_ptp(char *itype, int iface, char *rip, int metric)
{
    char buf[128];
    char win[32];
    int res;
    if (window == 0)
	win[0] = 0;
    else
    	sprintf(win,"window %d",window);
    if (debug&DEBUG_VERBOSE)
	syslog(LOG_INFO, "Setting pointopoint route for %s%d",itype,iface);
    sprintf(buf,"%s add %s metric %d %s dev %s%d",
	path_route,rip,metric,win,itype,iface); 
    res = system(buf);
    report_system_result(res,buf);
}

/*
 * Add in a direct and default route to the slip link.
 * The default route is only added if the "default" option was
 * requested by the user.
 */

void add_routes(char *itype, int iface, char *lip, char *rip, int metric)
{
    char buf[128];
    char win[32];
    int res;

    if (debug&DEBUG_VERBOSE)
	syslog(LOG_INFO,"Establishing routes for %s%d",itype,iface);

    if (window == 0)
	win[0] = 0;
    else
    	sprintf(win,"window %d",window);
    sprintf(buf,"INTERFACE\n%s%d\n%s\n%s\n", itype, iface, lip, rip);
    if (monitors) mon_write(MONITOR_INTERFACE,buf,strlen(buf));

    /* Add in a default route for the link */
    /* FIXME: should this refuse to add if a default route exists? */
    /* FIXME: Should not report an error if the error was just that the
     *        route we tried to add already exists.
     *        (A new error reported by more recent kernels.)
     */
    if (default_route) {
	sprintf(buf,"%s add default metric %d %s netmask 0.0.0.0 dev %s%d",
		path_route,metric,win,itype,iface);
        res = system(buf);
    	report_system_result(res,buf);
    }

    /* call addroute script */
    if (addroute) {
        sprintf(buf,"%s %s%d %s %s %s %d %d",
	    addroute,itype,iface,(netmask)?netmask:"default",
	    lip,rip,metric,window);
	res = system(buf);
    	report_system_result(res,buf);
    }

    if (proxyarp) set_proxyarp(inet_addr(rip));
}

/*
 * Call the delroute script.
 */
void del_routes(char *itype, int iface, char *lip, char *rip, int metric)
{
    char buf[128];
    int res;

    if (debug&DEBUG_VERBOSE)
	syslog(LOG_INFO,"Removing routes for %s%d",itype,iface);

    if (proxyarp) clear_proxyarp(inet_addr(rip));

    /* FIXME: should delete routes be added here?
     * We may be bringing a connection "down" that always has an up interface.
     * Question: should we just delete all routes through the interface?
     * That might be the best thing. On the other hand it confuses the
     * whole question of the need for a delroute script.
     */
    if (default_route) {
	sprintf(buf,"%s del default metric %d netmask 0.0.0.0 dev %s%d",path_route,metric,itype,iface);
        system(buf);
    }

    if (debug&DEBUG_VERBOSE)
	syslog(LOG_INFO, "Deleting pointopoint route for %s%d",itype,iface);
    sprintf(buf,"%s del %s metric %d dev %s%d",path_route,rip,metric,itype,iface); 
    res = system(buf);

    if (delroute) {
	/* call delroute <iface> <netmask> <local> <remote> */
        sprintf(buf,"%s %s%d %s %s %s %d",
	    delroute,itype,iface,(netmask)?netmask:"default",lip,rip,metric);
        res = system(buf);
        report_system_result(res,buf);
    }
}