~ubuntu-branches/ubuntu/hardy/openvpn/hardy-proposed

« back to all changes in this revision

Viewing changes to route.h

  • Committer: Bazaar Package Importer
  • Author(s): Alberto Gonzalez Iniesta
  • Date: 2004-06-10 15:59:39 UTC
  • Revision ID: james.westby@ubuntu.com-20040610155939-dcmtiuvcoqnwek62
Tags: upstream-1.6.0
ImportĀ upstreamĀ versionĀ 1.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  OpenVPN -- An application to securely tunnel IP networks
 
3
 *             over a single TCP/UDP port, with support for SSL/TLS-based
 
4
 *             session authentication and key exchange,
 
5
 *             packet encryption, packet authentication, and
 
6
 *             packet compression.
 
7
 *
 
8
 *  Copyright (C) 2002-2004 James Yonan <jim@yonan.net>
 
9
 *
 
10
 *  This program is free software; you can redistribute it and/or modify
 
11
 *  it under the terms of the GNU General Public License as published by
 
12
 *  the Free Software Foundation; either version 2 of the License, or
 
13
 *  (at your option) any later version.
 
14
 *
 
15
 *  This program is distributed in the hope that it will be useful,
 
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *  GNU General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU General Public License
 
21
 *  along with this program (see the file COPYING included with this
 
22
 *  distribution); if not, write to the Free Software Foundation, Inc.,
 
23
 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
24
 */
 
25
 
 
26
/*
 
27
 * Support routines for adding/deleting network routes.
 
28
 */
 
29
 
 
30
#ifndef ROUTE_H
 
31
#define ROUTE_H
 
32
 
 
33
#define MAX_ROUTES 50
 
34
 
 
35
#if defined(TARGET_FREEBSD)
 
36
 
 
37
/* all of this is taken from <net/route.h> in FreeBSD */
 
38
#define RTA_DST     0x1
 
39
#define RTA_GATEWAY 0x2
 
40
#define RTA_NETMASK 0x4
 
41
 
 
42
#define RTM_GET     0x4
 
43
#define RTM_VERSION 5
 
44
 
 
45
#define RTF_UP      0x1
 
46
#define RTF_GATEWAY 0x2
 
47
 
 
48
/*
 
49
 * These numbers are used by reliable protocols for determining
 
50
 * retransmission behavior and are included in the routing structure.
 
51
 */
 
52
struct rt_metrics {
 
53
        u_long  rmx_locks;      /* Kernel must leave these values alone */
 
54
        u_long  rmx_mtu;        /* MTU for this path */
 
55
        u_long  rmx_hopcount;   /* max hops expected */
 
56
        u_long  rmx_expire;     /* lifetime for route, e.g. redirect */
 
57
        u_long  rmx_recvpipe;   /* inbound delay-bandwidth product */
 
58
        u_long  rmx_sendpipe;   /* outbound delay-bandwidth product */
 
59
        u_long  rmx_ssthresh;   /* outbound gateway buffer limit */
 
60
        u_long  rmx_rtt;        /* estimated round trip time */
 
61
        u_long  rmx_rttvar;     /* estimated rtt variance */
 
62
        u_long  rmx_pksent;     /* packets sent using this route */
 
63
        u_long  rmx_filler[4];  /* will be used for T/TCP later */
 
64
};
 
65
 
 
66
 
 
67
/*
 
68
 * Structures for routing messages.
 
69
 */
 
70
struct rt_msghdr {
 
71
        u_short rtm_msglen;     /* to skip over non-understood messages */
 
72
        u_char  rtm_version;    /* future binary compatibility */
 
73
        u_char  rtm_type;       /* message type */
 
74
        u_short rtm_index;      /* index for associated ifp */
 
75
        int     rtm_flags;      /* flags, incl. kern & message, e.g. DONE */
 
76
        int     rtm_addrs;      /* bitmask identifying sockaddrs in msg */
 
77
        pid_t   rtm_pid;        /* identify sender */
 
78
        int     rtm_seq;        /* for sender to identify action */
 
79
        int     rtm_errno;      /* why failed */
 
80
        int     rtm_use;        /* from rtentry */
 
81
        u_long  rtm_inits;      /* which metrics we are initializing */
 
82
        struct  rt_metrics rtm_rmx; /* metrics themselves */
 
83
};
 
84
 
 
85
#endif
 
86
 
 
87
 
 
88
struct route_special_addr
 
89
{
 
90
  in_addr_t remote_endpoint;
 
91
  bool remote_endpoint_defined;
 
92
  in_addr_t net_gateway;
 
93
  bool net_gateway_defined;
 
94
  in_addr_t remote_host;
 
95
  bool remote_host_defined;
 
96
};
 
97
 
 
98
struct route_option {
 
99
  const char *network;
 
100
  const char *netmask;
 
101
  const char *gateway;
 
102
  const char *metric;
 
103
};
 
104
 
 
105
struct route_option_list {
 
106
  int n;
 
107
  bool redirect_default_gateway;
 
108
  struct route_option routes[MAX_ROUTES];
 
109
};
 
110
 
 
111
struct route {
 
112
  bool defined;
 
113
  const struct route_option *option;
 
114
  in_addr_t network;
 
115
  in_addr_t netmask;
 
116
  in_addr_t gateway;
 
117
  bool metric_defined;
 
118
  int metric;
 
119
};
 
120
 
 
121
struct route_list {
 
122
  bool routes_added;
 
123
  struct route_special_addr spec;
 
124
  bool redirect_default_gateway;
 
125
  bool did_redirect_default_gateway;
 
126
 
 
127
  int n;
 
128
  struct route routes[MAX_ROUTES];
 
129
};
 
130
 
 
131
void add_route_to_option_list (struct route_option_list *l,
 
132
                               const char *network,
 
133
                               const char *netmask,
 
134
                               const char *gateway,
 
135
                               const char *metric);
 
136
 
 
137
void clear_route_list (struct route_list *rl);
 
138
 
 
139
bool init_route_list (struct route_list *rl,
 
140
                      const struct route_option_list *opt,
 
141
                      const char *remote_endpoint,
 
142
                      in_addr_t remote_host);
 
143
 
 
144
void add_routes (struct route_list *rl,
 
145
                 bool delete_first);
 
146
 
 
147
void delete_routes (struct route_list *rl);
 
148
void setenv_routes (const struct route_list *rl);
 
149
 
 
150
void print_route_options (const struct route_option_list *rol,
 
151
                          int level);
 
152
 
 
153
void print_routes (const struct route_list *rl, int level);
 
154
 
 
155
 
 
156
#endif