~ubuntu-branches/ubuntu/precise/openvpn/precise-updates

« back to all changes in this revision

Viewing changes to helper.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2009-05-05 14:25:37 UTC
  • mfrom: (1.1.12 upstream) (10.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090505142537-vq38z4k80bpltxb9
Tags: 2.1~rc15-1ubuntu1
* Merge from debian unstable (LP: #372358), remaining changes:
  - debian/openvpn.init.d: 
    - Do not use start-stop-daemon and use < /dev/null to avoid blocking boot
    - show per-VPN result messages 
    - add "--script-security 2" by default for backwards compatibility
    - Added lsb-base>=3.2-14 depend to allow status_of_proc()

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *             packet encryption, packet authentication, and
6
6
 *             packet compression.
7
7
 *
8
 
 *  Copyright (C) 2002-2008 Telethra, Inc. <sales@openvpn.net>
 
8
 *  Copyright (C) 2002-2008 OpenVPN Technologies, Inc. <sales@openvpn.net>
9
9
 *
10
10
 *  This program is free software; you can redistribute it and/or modify
11
11
 *  it under the terms of the GNU General Public License version 2
96
96
  return BSTR (&out);
97
97
}
98
98
 
 
99
static const char *
 
100
print_str (const char *str, struct gc_arena *gc)
 
101
{
 
102
  struct buffer out = alloc_buf_gc (128, gc);
 
103
  buf_printf (&out, "%s", str);
 
104
  return BSTR (&out);
 
105
}
 
106
 
99
107
static void
100
108
helper_add_route (const in_addr_t network, const in_addr_t netmask, struct options *o)
101
109
{
158
166
   *
159
167
   * if tap OR (tun AND topology == subnet):
160
168
   *   ifconfig 10.8.0.1 255.255.255.0
161
 
   *   ifconfig-pool-constraint 10.8.0.0 255.255.255.0
162
169
   *   if !nopool: 
163
170
   *     ifconfig-pool 10.8.0.2 10.8.0.254 255.255.255.0
164
171
   *   push "route-gateway 10.8.0.1"
184
191
      if (o->shared_secret_file)
185
192
        msg (M_USAGE, "--server and --secret cannot be used together (you must use SSL/TLS keys)");
186
193
 
187
 
      if (o->ifconfig_pool_defined)
 
194
      if (!(o->server_flags & SF_NOPOOL) && o->ifconfig_pool_defined)
188
195
        msg (M_USAGE, "--server already defines an ifconfig-pool, so you can't also specify --ifconfig-pool explicitly");
189
196
 
190
197
      if (!(dev == DEV_TYPE_TAP || dev == DEV_TYPE_TUN))
245
252
                  o->ifconfig_pool_start = o->server_network + 2;
246
253
                  o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - 2;
247
254
                  ifconfig_pool_verify_range (M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
248
 
                  o->ifconfig_pool_netmask = o->server_netmask;
249
255
                }
250
 
 
 
256
              o->ifconfig_pool_netmask = o->server_netmask;
 
257
                  
251
258
              push_option (o, print_opt_route_gateway (o->server_network + 1, &o->gc), M_USAGE);
252
259
            }
253
260
          else
272
279
              o->ifconfig_pool_start = o->server_network + 2;
273
280
              o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - 1;
274
281
              ifconfig_pool_verify_range (M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
275
 
              o->ifconfig_pool_netmask = o->server_netmask;
276
282
            }
 
283
          o->ifconfig_pool_netmask = o->server_netmask;
277
284
 
278
285
          push_option (o, print_opt_route_gateway (o->server_network + 1, &o->gc), M_USAGE);
279
286
        }
320
327
      if (o->client)
321
328
        msg (M_USAGE, "--server-bridge and --client cannot be used together");
322
329
 
323
 
      if (o->ifconfig_pool_defined)
 
330
      if (!(o->server_flags & SF_NOPOOL) && o->ifconfig_pool_defined)
324
331
        msg (M_USAGE, "--server-bridge already defines an ifconfig-pool, so you can't also specify --ifconfig-pool explicitly");
325
332
 
326
333
      if (o->shared_secret_file)
439
446
        }
440
447
    }
441
448
}
 
449
 
 
450
/*
 
451
 *
 
452
 * HELPER DIRECTIVE:
 
453
 *
 
454
 * tcp-nodelay
 
455
 *
 
456
 * EXPANDS TO:
 
457
 *
 
458
 * if mode server:
 
459
 *   socket-flags TCP_NODELAY
 
460
 *   push "socket-flags TCP_NODELAY"
 
461
 */
 
462
void
 
463
helper_tcp_nodelay (struct options *o)
 
464
{
 
465
#if P2MP_SERVER
 
466
  if (o->server_flags & SF_TCP_NODELAY_HELPER)
 
467
    {
 
468
      if (o->mode == MODE_SERVER)
 
469
        {
 
470
          o->sockflags |= SF_TCP_NODELAY;         
 
471
          push_option (o, print_str ("socket-flags TCP_NODELAY", &o->gc), M_USAGE);
 
472
        }
 
473
      else
 
474
        {
 
475
          ASSERT (0);
 
476
        }
 
477
    }
 
478
#endif
 
479
}