File: routing.c

package info (click to toggle)
pptp-linux 1.7.2-5
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 432 kB
  • ctags: 559
  • sloc: ansic: 3,471; perl: 134; makefile: 109
file content (79 lines) | stat: -rw-r--r-- 2,436 bytes parent folder | download | duplicates (3)
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
/*
    routing.c, manipulating routing table for PPTP Client
    Copyright (C) 2006  James Cameron <quozl@us.netrek.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include "routing.h"

/* route to the server */
char *route;

/*

Design discussion.

The primary task of this module is to add a host route to the PPTP
server so that the kernel continues to deliver PPTP control and data
connection packets to the server despite the new PPP interface that is
created.  The flag --no-host-route is to disable this (not yet implemented).

A secondary task may be to implement all-to-tunnel routing if the
appropriate flag is specified on the command line.  The flag
--route-all is to implement this (not yet implemented).

Caveat.

It is not possible from the "ip route" command to determine if a host
route already exists, so it isn't practical to put the routing table
back exactly as it was.

We have a choice of either leaving our route lying around, or
destroying a route that the user had pre-arranged.  Both are
unfortunate.  The flag --remove-host-route is to remove the route
regardless (not yet implemented).

*/

void routing_init(char *ip) {
  char buf[256];
  snprintf(buf, 255, "/bin/ip route get %s", ip);
  FILE *p = popen(buf, "r");
  fgets(buf, 255, p);
  /* TODO: check for failure of fgets */
  route = strdup(buf);
  pclose(p);
  /* TODO: check for failure of command */
}

void routing_start() {
  char buf[256];
  snprintf(buf, 255, "/bin/ip route replace %s", route);
  FILE *p = popen(buf, "r");
  pclose(p);
}

void routing_end() {
  char buf[256];
  snprintf(buf, 255, "/bin/ip route delete %s", route);
  FILE *p = popen(buf, "r");
  pclose(p);
}