• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Révision87979cc6cd8c8b28d938de3333cf1e324b361ff3 (tree)
l'heure2015-10-14 19:37:40
Auteurphabrics <phabrics@phab...>
Commiterphabrics

Message de Log

Added openvpn functionality to get hardware address and set ipv6 address. Moved setuid to end at GTK init so that all init code that needed it could run before getting there in the main thread.

Change Summary

Modification

--- a/contrib/tme-0.8/configure.ac
+++ b/contrib/tme-0.8/configure.ac
@@ -635,9 +635,10 @@ linux*)
635635 AC_DEFINE_UNQUOTED([TARGET_PREFIX], ["L"], [Target prefix])
636636 CPPFLAGS="${CPPFLAGS-}"
637637 DEV_TAP_FILENAME='"\"/dev/net/tun\""'
638- SETCAP="setcap cap_sys_nice,cap_net_admin,cap_net_raw+ep"
638+ SETCAP="chmod u+s"
639+# SETCAP="setcap cap_sys_nice,cap_net_admin,cap_net_raw+ep"
639640 ;;
640-mingw*)
641+mingw*|cygwin*)
641642 AC_DEFINE([TARGET_WIN32], [1], [Are we running WIN32?])
642643 AC_DEFINE_UNQUOTED([TARGET_PREFIX], ["W"], [Target prefix])
643644 CPPFLAGS="${CPPFLAGS} -DWIN32_LEAN_AND_MEAN"
@@ -983,7 +984,7 @@ fi
983984
984985 for tme_thread_type in ${tme_thread_types}; do
985986 case "x${tme_thread_type}" in
986-xpthreads | xposix) CPPFLAGS="${CPPFLAGS-} -DTME_THREADS_POSIX -D_GNU_SOURCE"
987+xpthreads | xposix) CPPFLAGS="${CPPFLAGS-} -DTME_THREADS_POSIX"
987988 # CFLAGS="${CFLAGS-} -pthread"
988989 ;;
989990 xglib) CPPFLAGS="${CPPFLAGS-} -DTME_THREADS_GLIB ${GLIB_CFLAGS}"
--- a/contrib/tme-0.8/host/bsd/bsd-bpf.c
+++ b/contrib/tme-0.8/host/bsd/bsd-bpf.c
@@ -604,7 +604,7 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_bsd,bpf) {
604604 rc = _tme_bsd_bpf_args(args, &ifr, &packet_buffer_size, delay_time, _output);
605605
606606 /* find the interface we will use: */
607- rc = tme_eth_ifaddrs_find(ifr.ifr_name, &ifa, NULL, NULL);
607+ rc = tme_eth_ifaddrs_find(ifr.ifr_name, AF_UNSPEC, &ifa, NULL, NULL);
608608
609609 if (rc != TME_OK) {
610610 tme_output_append_error(_output, _("couldn't find an interface %s"), ifr.ifr_name);
@@ -752,7 +752,6 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_bsd,bpf) {
752752 return (errno);
753753 }
754754
755- setuid(getuid());
756755 #endif
757756
758757 return tme_eth_init(element, bpf_fd, packet_buffer_size, delay_time, NULL, _tme_bsd_bpf_connections_new);
--- a/contrib/tme-0.8/host/eth/eth-if.h
+++ b/contrib/tme-0.8/host/eth/eth-if.h
@@ -185,7 +185,8 @@ int tme_eth_if_find _TME_P((_tme_const char *,
185185
186186 #endif
187187 #ifdef HAVE_IFADDRS_H
188-int tme_eth_ifaddrs_find _TME_P((_tme_const char *,
188+int tme_eth_ifaddrs_find _TME_P((_tme_const char *,
189+ int family,
189190 struct ifaddrs **,
190191 tme_uint8_t **,
191192 unsigned int *));
--- a/contrib/tme-0.8/host/eth/eth-impl.c
+++ b/contrib/tme-0.8/host/eth/eth-impl.c
@@ -364,7 +364,7 @@ static int
364364 _tme_eth_config(struct tme_ethernet_connection *conn_eth,
365365 struct tme_ethernet_config *config)
366366 {
367- abort();
367+ assert(0);
368368 }
369369
370370 /* this is called when control lines change: */
@@ -651,10 +651,11 @@ tme_eth_if_find(const char *ifr_name_user, struct ifreq **_ifreq, tme_uint8_t **
651651 #ifdef HAVE_IFADDRS_H
652652 /* this finds a network interface via the ifaddrs api: */
653653 int
654-tme_eth_ifaddrs_find(const char *ifa_name_user, struct ifaddrs **_ifaddr, tme_uint8_t **_if_addr, unsigned int *_if_addr_size)
654+tme_eth_ifaddrs_find(const char *ifa_name_user, int family, struct ifaddrs **_ifaddr, tme_uint8_t **_if_addr, unsigned int *_if_addr_size)
655655 {
656656 struct ifaddrs *ifaddr, *ifa;
657657 struct ifaddrs *ifa_user = NULL;
658+ char ifa_name[INET6_ADDRSTRLEN];
658659 #if defined(HAVE_AF_LINK) || defined(HAVE_AF_PACKET)
659660 struct ifaddrs *link_ifaddrs[20]; /* FIXME - magic constant. */
660661 size_t link_ifaddrs_count;
@@ -695,43 +696,53 @@ tme_eth_ifaddrs_find(const char *ifa_name_user, struct ifaddrs **_ifaddr, tme_ui
695696 }
696697 #endif
697698
698- /* ignore this interface if it doesn't do IP: */
699- /* XXX is this actually important? */
700- if (ifa->ifa_addr->sa_family != AF_INET) {
701- continue;
702- }
703-
704699 /* ignore this interface if it isn't up and running: */
705700 if ((ifa->ifa_flags & (IFF_UP | IFF_RUNNING))
706701 != (IFF_UP | IFF_RUNNING)) {
707702 continue;
708703 }
709704
705+ switch(family) {
706+ case AF_UNSPEC:
707+ strncpy(ifa_name, ifa->ifa_name, IFNAMSIZ);
708+ break;
709+ case AF_INET:
710+ if(ifa->ifa_addr->sa_family != AF_INET) continue;
711+ inet_ntop(family, &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr, ifa_name, INET_ADDRSTRLEN);
712+ break;
713+ case AF_INET6:
714+ if(ifa->ifa_addr->sa_family != AF_INET6) continue;
715+ inet_ntop(family, &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr, ifa_name, INET6_ADDRSTRLEN);
716+ break;
717+ default:
718+ return EAFNOSUPPORT;
719+ }
720+
710721 /* if we don't have an interface yet, take this one depending on
711722 whether the user asked for an interface by name or not. if he
712723 did, and this is it, take this one. if he didn't, and this
713724 isn't a loopback interface, take this one: */
714- if (ifa_user == NULL
715- && ((ifa_name_user != NULL && strlen(ifa_name_user))
716- ? !strncmp(ifa->ifa_name, ifa_name_user, strlen(ifa->ifa_name))
717- : !(ifa->ifa_flags & IFF_LOOPBACK))) {
725+ if ((ifa_name_user != NULL && strlen(ifa_name_user))
726+ ? !strncmp(ifa_name, ifa_name_user, strlen(ifa_name))
727+ : !(ifa->ifa_flags & IFF_LOOPBACK)) {
718728 ifa_user = ifa;
719729 break;
720730 }
721-
731+
722732 }
723-
733+
724734 /* if we don't have an interface to return: */
725735 if (ifa_user == NULL) {
726736 return ENOENT;
727737 }
728-
738+
729739 /* return this interface: */
730- *_ifaddr = (struct ifaddrs *) tme_memdup(ifa_user, sizeof(struct ifaddrs));
731-
740+ if (_ifaddr != NULL)
741+ *_ifaddr = (struct ifaddrs *) tme_memdup(ifa_user, sizeof(struct ifaddrs));
742+
732743 /* assume that we can't find this interface's hardware address: */
733744 if (_if_addr != NULL) {
734- *_if_addr = NULL;
745+ *_if_addr = NULL;
735746 }
736747 if (_if_addr_size != NULL) {
737748 *_if_addr_size = 0;
@@ -848,7 +859,7 @@ tme_eth_connections_new(struct tme_element *element,
848859 conn->tme_connection_score = tme_ethernet_connection_score;
849860 conn->tme_connection_make = _tme_eth_connection_make;
850861 conn->tme_connection_break = _tme_eth_connection_break;
851-
862+
852863 /* fill in the Ethernet connection: */
853864 conn_eth->tme_ethernet_connection_config = _tme_eth_config;
854865 conn_eth->tme_ethernet_connection_ctrl = _tme_eth_ctrl;
--- a/contrib/tme-0.8/host/gtk/gtk-display.c
+++ b/contrib/tme-0.8/host/gtk/gtk-display.c
@@ -285,7 +285,7 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_gtk,display) {
285285 }
286286
287287 /* call gtk_init if we haven't already: */
288- // tme_threads_gtk_init();
288+ tme_threads_gtk_init();
289289
290290 /* start our data structure: */
291291 display = tme_new0(struct tme_gtk_display, 1);
--- a/contrib/tme-0.8/host/openvpn/tap.c
+++ b/contrib/tme-0.8/host/openvpn/tap.c
@@ -38,70 +38,71 @@
3838 #include "syshead.h"
3939 #include "tun.h"
4040
41-/* macros: */
42-/* device names: */
43-#define TME_DEV (0)
44-#define TME_DEV_TYPE (1)
45-#define TME_DEV_NODE (2)
46-#define TME_DEV_ADDR (3)
47-#define TME_DEV_TOTAL (4)
48-
49-/* interface addresses: */
50-#define TME_IP_ADDRS_INET (0)
51-#define TME_IP_ADDRS_NETMASK (1)
52-#define TME_IP_ADDRS_TOTAL (2)
53-
54-/* retrieve ethernet arguments */
55-int _tme_openvpn_tap_args(const char * const args[],
56- char *devs[],
57- struct in_addr *ip_addrs,
58- char **_output)
59-{
41+/* the new TAP function: */
42+TME_ELEMENT_SUB_NEW_DECL(tme_host_openvpn,tap) {
43+ int rc;
44+ struct gc_arena gc = gc_new ();
45+ const char *dev, *dev_type, *dev_node, *dev_addr;
46+ const char *inet, *netmask, *inet6, *remote6, *netbits;
47+ unsigned char *hwaddr;
48+ unsigned int hwaddr_len;
49+ struct tuntap *tt;
6050 int arg_i;
6151 int usage;
6252
6353 /* check our arguments: */
6454 usage = 0;
6555
66- memset(ip_addrs, 0, TME_IP_ADDRS_TOTAL * sizeof(struct in_addr));
67-
56+ dev = dev_type = dev_node = dev_addr =
57+ inet = netmask = inet6 = remote6 = netbits = NULL;
58+
6859 arg_i = 1;
6960
7061 for (;;) {
7162 /* the interface we're supposed to use: */
7263 if (TME_ARG_IS(args[arg_i + 0], "dev")
7364 && args[arg_i + 1] != NULL) {
74- devs[TME_DEV] = args[arg_i + 1];
65+ dev = args[arg_i + 1];
7566 }
7667
7768 else if (TME_ARG_IS(args[arg_i + 0], "dev-type")
7869 && args[arg_i + 1] != NULL) {
79- devs[TME_DEV_TYPE] = args[arg_i + 1];
70+ dev_type = args[arg_i + 1];
8071 }
8172
8273 else if (TME_ARG_IS(args[arg_i + 0], "dev-node")
8374 && args[arg_i + 1] != NULL) {
84- devs[TME_DEV_NODE] = args[arg_i + 1];
75+ dev_node = args[arg_i + 1];
8576 }
8677
8778 else if (TME_ARG_IS(args[arg_i + 0], "dev-addr")
8879 && args[arg_i + 1] != NULL) {
89- devs[TME_DEV_ADDR] = args[arg_i + 1];
80+ dev_addr = args[arg_i + 1];
9081 }
9182
9283 else if(TME_ARG_IS(args[arg_i + 0], "inet")
9384 && args[arg_i + 1] != NULL) {
94- inet_pton(AF_INET, args[arg_i + 1], ip_addrs + TME_IP_ADDRS_INET);
85+ inet = args[arg_i + 1];
9586 }
96- /*
87+
88+ else if (TME_ARG_IS(args[arg_i + 0], "netmask")
89+ && args[arg_i + 1] != NULL) {
90+ netmask = args[arg_i + 1];
91+ }
92+
9793 else if(TME_ARG_IS(args[arg_i + 0], "inet6")
9894 && args[arg_i + 1] != NULL) {
99- inet_pton(AF_INET6, args[arg_i + 1], ip_addrs + TME_IP_ADDRS_INET6);
95+ inet6 = args[arg_i + 1];
10096 }
101- */
102- else if (TME_ARG_IS(args[arg_i + 0], "netmask")
97+
98+ else if(TME_ARG_IS(args[arg_i + 0], "remote6")
99+ && args[arg_i + 1] != NULL) {
100+ remote6 = args[arg_i + 1];
101+ }
102+
103+ else if (TME_ARG_IS(args[arg_i + 0], "netbits")
103104 && args[arg_i + 1] != NULL) {
104- inet_pton(AF_INET, args[arg_i + 1], ip_addrs + TME_IP_ADDRS_NETMASK);
105+ netbits = args[arg_i + 1];
105106 }
106107
107108 /* if we ran out of arguments: */
@@ -123,7 +124,7 @@ int _tme_openvpn_tap_args(const char * const args[],
123124
124125 if (usage) {
125126 tme_output_append_error(_output,
126- "%s %s [ dev %s ] [ dev-type %s ] [ dev-node %s ] [ dev-addr %s ] [ inet %s ] [ netmask %s ]",
127+ "%s %s [ dev %s ] [ dev-type %s ] [ dev-node %s ] [ dev-addr %s ] [ inet %s ] [ netmask %s ] [ inet6 %s] [remote6 %s]",
127128 _("usage:"),
128129 args[0],
129130 _("NAME"),
@@ -131,77 +132,72 @@ int _tme_openvpn_tap_args(const char * const args[],
131132 _("NODE"),
132133 _("LLADDR"),
133134 _("IPADDRESS"),
134- _("IPADDRESS"));
135+ _("IPADDRESS"),
136+ _("IP6ADDRESS"),
137+ _("IP6ADDRESS"));
135138 return (EINVAL);
136139 }
137- return (TME_OK);
138-}
139-
140-/* the new TAP function: */
141-TME_ELEMENT_SUB_NEW_DECL(tme_host_openvpn,tap) {
142- int i;
143- struct gc_arena gc = gc_new ();
144- char *devs[TME_DEV_TOTAL];
145- char tap_hosts[TME_IP_ADDRS_TOTAL][NI_MAXHOST];
146- struct in_addr tap_addrs[TME_IP_ADDRS_TOTAL];
147- unsigned char *hwaddr;
148- unsigned int hwaddr_len;
149- struct tuntap *tt;
150140
151- for(i=0;i<TME_DEV_TOTAL;i++) {
152- devs[i]=NULL;
153- }
154- /* get the arguments: */
155- _tme_openvpn_tap_args(args, devs, tap_addrs, _output);
156-
157- if(!devs[TME_DEV]) devs[TME_DEV] = "tap";
141+ if(!dev) dev = "tap";
158142
159- for(i=0;i<TME_IP_ADDRS_TOTAL;i++) {
160- inet_ntop(AF_INET, &tap_addrs[i], tap_hosts[i], NI_MAXHOST);
161- }
162143 tme_log(&element->tme_element_log_handle, 0, TME_OK,
163144 (&element->tme_element_log_handle,
164- "trying tap device (%s, %s, %s) with link-layer address %s, ip address %s, netmask %s",
165- ((devs[TME_DEV]) ? (devs[TME_DEV]) : ""),
166- ((devs[TME_DEV_TYPE]) ? (devs[TME_DEV_TYPE]) : ""),
167- ((devs[TME_DEV_NODE]) ? (devs[TME_DEV_TYPE]) : ""),
168- ((devs[TME_DEV_ADDR]) ? (devs[TME_DEV_ADDR]) : ""),
169- tap_hosts[TME_IP_ADDRS_INET],
170- tap_hosts[TME_IP_ADDRS_NETMASK]));
171-
145+ "trying tap device (%s, type %s, node %s) with addresses: link %s, ip %s/%s, ip6 %s/%s prefixlen %s",
146+ dev,
147+ (dev_type) ? (dev_type) : "",
148+ (dev_node) ? (dev_node) : "",
149+ (dev_addr) ? (dev_addr) : "",
150+ (inet) ? (inet) : "",
151+ (netmask) ? (netmask) : "",
152+ (inet6) ? (inet6) : "",
153+ (remote6) ? (remote6) : "",
154+ (netbits) ? (netbits) : ""));
155+
172156 error_reset();
173- tt = init_tun(devs[TME_DEV],
174- devs[TME_DEV_TYPE],
157+ tt = init_tun(dev,
158+ dev_type,
175159 TOP_SUBNET,
176- tap_hosts[TME_IP_ADDRS_INET],
177- tap_hosts[TME_IP_ADDRS_NETMASK],
178- NULL, 0, NULL, 0, 0, 0, NULL);
160+ inet,
161+ netmask,
162+ inet6,
163+ (netbits) ? (atoi(netbits)) : (0),
164+ remote6,
165+ 0,
166+ 0,
167+ 0,
168+ NULL);
179169
180170 if(ifconfig_order() == IFCONFIG_BEFORE_TUN_OPEN) {
181171 /* guess actual tun/tap unit number that will be returned
182172 by open_tun */
183- const char *guess = guess_tuntap_dev(devs[TME_DEV],
184- devs[TME_DEV_TYPE],
185- devs[TME_DEV_NODE],
173+ const char *guess = guess_tuntap_dev(dev,
174+ dev_type,
175+ dev_node,
186176 &gc);
187177 do_ifconfig(tt, guess, TME_ETHERNET_FRAME_MAX, NULL);
188178 }
189179
190180 /* open the tun device */
191- open_tun(devs[TME_DEV],
192- devs[TME_DEV_TYPE],
193- devs[TME_DEV_NODE],
181+ open_tun(dev,
182+ dev_type,
183+ dev_node,
194184 tt);
195185
196186 /* set the hardware address */
197- if(devs[TME_DEV_ADDR])
198- set_lladdr(tt->actual_name, devs[TME_DEV_ADDR], NULL);
199-
187+ if(dev_addr)
188+ set_lladdr(tt->actual_name, dev_addr, NULL);
189+
200190 /* do ifconfig */
201191 if(ifconfig_order() == IFCONFIG_AFTER_TUN_OPEN) {
202192 do_ifconfig(tt, tt->actual_name, TME_ETHERNET_FRAME_MAX, NULL);
203193 }
204-
194+
195+ /* find the interface we will use: */
196+ if(inet || inet6)
197+ rc = tme_eth_ifaddrs_find((inet) ? (inet) : (inet6),
198+ (inet) ? (AF_INET) : (AF_INET6),
199+ NULL, &hwaddr, &hwaddr_len);
200+
205201 return tme_eth_init(element, tt->fd, 4096, NULL, hwaddr, NULL);
206-
202+
207203 }
--- a/contrib/tme-0.8/host/tun/tun-tap.c
+++ b/contrib/tme-0.8/host/tun/tun-tap.c
@@ -858,7 +858,7 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_tun,tap) {
858858 close(dummy_fd);
859859
860860 /* find the interface we will use: */
861- rc = tme_eth_ifaddrs_find(TAPIF, &ifa, &hwaddr, &hwaddr_len);
861+ rc = tme_eth_ifaddrs_find(TAPIF, AF_UNSPEC, &ifa, &hwaddr, &hwaddr_len);
862862
863863 for(i=0;i<TME_IP_ADDRS_TOTAL;i++) {
864864 if((rc = getnameinfo(*(struct sockaddr **)((char *)ifa + ifa_offs[i]),
@@ -901,7 +901,7 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_tun,tap) {
901901 "trying nat interface %s", NATIF));
902902
903903 /* find the interface we will use: */
904- rc = tme_eth_ifaddrs_find(NATIF, &ifa, NULL, NULL);
904+ rc = tme_eth_ifaddrs_find(NATIF, AF_UNSPEC, &ifa, NULL, NULL);
905905
906906 if (rc != TME_OK) {
907907 tme_output_append_error(_output, _("couldn't find an interface %s"), NATIF);
@@ -1281,11 +1281,6 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_tun,tap) {
12811281 close(dummy_fd);
12821282 #endif // TME_DO_APF
12831283
1284-#ifdef SIOCAIFADDR
1285- // For BSD, we run setuid until here
1286- setuid(getuid());
1287-#endif
1288-
12891284 return tme_eth_init(element, tap_fd, 4096, NULL, hwaddr, _tme_tun_tap_connections_new);
12901285
12911286 #undef TAPINET
--- a/contrib/tme-0.8/tmesh/tmesh-threads.c
+++ b/contrib/tme-0.8/tmesh/tmesh-threads.c
@@ -57,6 +57,11 @@ void tme_threads_gtk_init(void)
5757 return;
5858 }
5959
60+ /* make sure we aren't running setuid */
61+#ifdef HAVE_SETUID
62+ setuid(getuid());
63+#endif
64+
6065 /* conjure up an argv. this is pretty bad: */
6166 argv = argv_buffer;
6267 argc = 0;
--- a/contrib/tme-0.8/tmesh/tmesh.c
+++ b/contrib/tme-0.8/tmesh/tmesh.c
@@ -846,9 +846,6 @@ main(int argc, char **argv)
846846 #endif // HAVE_PTHREAD_SETSCHEDPARAM
847847 #endif
848848
849- if(using_gtk)
850- tme_threads_gtk_init();
851-
852849 /* initialize libtmesh: */
853850 (void) tmesh_init();
854851
@@ -924,6 +921,9 @@ main(int argc, char **argv)
924921 tme_thread_create(&tmesh_thread, (tme_thread_t) _tmesh_th, NULL);
925922 }
926923
924+ if(using_gtk)
925+ tme_threads_gtk_init();
926+
927927 /* run the threads: */
928928 tme_threads_run();
929929