Deleted Added
full compact
bundle.c (51517) bundle.c (51525)
1/*-
2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/usr.sbin/ppp/bundle.c 51517 1999-09-21 19:37:00Z brian $
26 * $FreeBSD: head/usr.sbin/ppp/bundle.c 51525 1999-09-22 00:40:47Z brian $
27 */
28
29#include <sys/param.h>
30#include <sys/socket.h>
31#include <netinet/in.h>
32#include <net/if.h>
33#include <net/if_tun.h> /* For TUNSIFMODE & TUNSLMODE */
34#include <arpa/inet.h>

--- 5 unchanged lines hidden (view full) ---

40#include <errno.h>
41#include <fcntl.h>
42#include <paths.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <string.h>
46#include <sys/uio.h>
47#include <sys/wait.h>
27 */
28
29#include <sys/param.h>
30#include <sys/socket.h>
31#include <netinet/in.h>
32#include <net/if.h>
33#include <net/if_tun.h> /* For TUNSIFMODE & TUNSLMODE */
34#include <arpa/inet.h>

--- 5 unchanged lines hidden (view full) ---

40#include <errno.h>
41#include <fcntl.h>
42#include <paths.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <string.h>
46#include <sys/uio.h>
47#include <sys/wait.h>
48#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
49#include <sys/linker.h>
50#endif
48#include <termios.h>
49#include <unistd.h>
50
51#include "layer.h"
52#include "defs.h"
53#include "command.h"
54#include "mbuf.h"
55#include "log.h"

--- 540 unchanged lines hidden (view full) ---

596}
597
598struct bundle *
599bundle_Create(const char *prefix, int type, const char **argv)
600{
601 static struct bundle bundle; /* there can be only one */
602 int enoentcount, err;
603 const char *ifname;
51#include <termios.h>
52#include <unistd.h>
53
54#include "layer.h"
55#include "defs.h"
56#include "command.h"
57#include "mbuf.h"
58#include "log.h"

--- 540 unchanged lines hidden (view full) ---

599}
600
601struct bundle *
602bundle_Create(const char *prefix, int type, const char **argv)
603{
604 static struct bundle bundle; /* there can be only one */
605 int enoentcount, err;
606 const char *ifname;
607#ifdef KLDSYM_LOOKUP
608 int kldtried;
609#endif
604#if defined(TUNSIFMODE) || defined(TUNSLMODE)
605 int iff;
606#endif
607
608 if (bundle.iface != NULL) { /* Already allocated ! */
609 log_Printf(LogALERT, "bundle_Create: There's only one BUNDLE !\n");
610 return NULL;
611 }
612
613 err = ENOENT;
614 enoentcount = 0;
610#if defined(TUNSIFMODE) || defined(TUNSLMODE)
611 int iff;
612#endif
613
614 if (bundle.iface != NULL) { /* Already allocated ! */
615 log_Printf(LogALERT, "bundle_Create: There's only one BUNDLE !\n");
616 return NULL;
617 }
618
619 err = ENOENT;
620 enoentcount = 0;
621#ifdef KLDSYM_LOOKUP
622 kldtried = 0;
623#endif
615 for (bundle.unit = 0; ; bundle.unit++) {
616 snprintf(bundle.dev.Name, sizeof bundle.dev.Name, "%s%d",
617 prefix, bundle.unit);
618 bundle.dev.fd = ID0open(bundle.dev.Name, O_RDWR);
619 if (bundle.dev.fd >= 0)
620 break;
621 else if (errno == ENXIO) {
624 for (bundle.unit = 0; ; bundle.unit++) {
625 snprintf(bundle.dev.Name, sizeof bundle.dev.Name, "%s%d",
626 prefix, bundle.unit);
627 bundle.dev.fd = ID0open(bundle.dev.Name, O_RDWR);
628 if (bundle.dev.fd >= 0)
629 break;
630 else if (errno == ENXIO) {
631#ifdef KLDSYM_LOOKUP
632 if (bundle.unit == 0 && !kldtried++) {
633 /*
634 * XXX: For some odd reason, FreeBSD (right now) allows if_tun.ko to
635 * load even when the kernel contains the tun device. This lookup
636 * should go away when this is fixed, leaving just the kldload().
637 * Note also that kldsym() finds static symbols...
638 */
639 char devsw[] = "tun_cdevsw";
640 struct kld_sym_lookup ksl = { sizeof ksl, devsw, 0, 0 };
641
642 if (kldsym(0, KLDSYM_LOOKUP, &ksl) == -1) {
643 if (ID0kldload("if_tun") != -1) {
644 bundle.unit--;
645 continue;
646 }
647 log_Printf(LogWARN, "kldload: if_tun: %s\n", strerror(errno));
648 }
649 }
650#endif
622 err = errno;
623 break;
624 } else if (errno == ENOENT) {
625 if (++enoentcount > 2)
626 break;
627 } else
628 err = errno;
629 }

--- 1111 unchanged lines hidden ---
651 err = errno;
652 break;
653 } else if (errno == ENOENT) {
654 if (++enoentcount > 2)
655 break;
656 } else
657 err = errno;
658 }

--- 1111 unchanged lines hidden ---