… | |
… | |
40 | #else |
40 | #else |
41 | #include <linux/if_tun.h> |
41 | #include <linux/if_tun.h> |
42 | #endif |
42 | #endif |
43 | #define DEFAULT_DEVICE "/dev/net/tun" |
43 | #define DEFAULT_DEVICE "/dev/net/tun" |
44 | |
44 | |
|
|
45 | #include "gettext.h" |
|
|
46 | |
45 | #include "conf.h" |
47 | #include "conf.h" |
46 | |
48 | |
47 | #if TEST_ETHEREMU |
49 | #if TEST_ETHEREMU |
48 | # define IF_istun |
50 | # define IF_istun |
49 | # include "ether_emu.C" |
51 | # include "ether_emu.C" |
… | |
… | |
51 | |
53 | |
52 | const char * |
54 | const char * |
53 | tap_device::info () |
55 | tap_device::info () |
54 | { |
56 | { |
55 | return _("Linux tun/tap device"); |
57 | return _("Linux tun/tap device"); |
|
|
58 | } |
|
|
59 | |
|
|
60 | const char * |
|
|
61 | tap_device::if_up () |
|
|
62 | { |
|
|
63 | return "/sbin/ifconfig $IFNAME hw ether $MAC mtu $MTU"; |
56 | } |
64 | } |
57 | |
65 | |
58 | tap_device::tap_device () |
66 | tap_device::tap_device () |
59 | { |
67 | { |
60 | struct ifreq ifr; |
68 | struct ifreq ifr; |
… | |
… | |
86 | strncpy (ifrname, ifr.ifr_name, IFNAMSIZ); |
94 | strncpy (ifrname, ifr.ifr_name, IFNAMSIZ); |
87 | ifrname [IFNAMSIZ] = 0; |
95 | ifrname [IFNAMSIZ] = 0; |
88 | } |
96 | } |
89 | else |
97 | else |
90 | { |
98 | { |
91 | slog (L_CRIT, _("unable to configure tun/tap interface: %s"), strerror (errno)); |
99 | slog (L_CRIT, _("unable to configure tun/tap interface, exiting: %s"), strerror (errno)); |
92 | exit (EXIT_FAILURE); |
100 | exit (EXIT_FAILURE); |
93 | } |
101 | } |
|
|
102 | |
|
|
103 | #if 0 |
|
|
104 | doesn't work |
|
|
105 | id2mac (THISNODE->id, &ifr.ifr_hwaddr.sa_data); |
|
|
106 | if (ioctl (fd, SIOCSIFHWADDR, &ifr)) |
|
|
107 | { |
|
|
108 | slog (L_ERR, _("cannot set MAC address for device %s, exiting: %s"), ifrname, strerror (errno)); |
|
|
109 | exit (EXIT_FAILURE); |
|
|
110 | } |
|
|
111 | #endif |
94 | |
112 | |
95 | if (ioctl (fd, TUNSETPERSIST, conf.ifpersist ? 1 : 0)) |
113 | if (ioctl (fd, TUNSETPERSIST, conf.ifpersist ? 1 : 0)) |
96 | slog (L_WARN, _("cannot set persistency mode for device %s: %s"), ifrname, strerror (errno)); |
114 | slog (L_WARN, _("cannot set persistency mode for device %s: %s"), ifrname, strerror (errno)); |
97 | |
115 | |
98 | slog (L_DEBUG, _("%s is a %s"), device, info ()); |
116 | slog (L_DEBUG, _("%s is a %s"), device, info ()); |