Fix bug in IP address parsing from gai
This commit is contained in:
parent
c767d81251
commit
6cb990d57d
@ -32,6 +32,8 @@
|
||||
#ifndef LWIP_LWIPOPTS_H
|
||||
#define LWIP_LWIPOPTS_H
|
||||
|
||||
#define LWIP_DEBUG 0
|
||||
|
||||
#ifdef LWIP_OPTTEST_FILE
|
||||
#include "lwipopts_test.h"
|
||||
#else /* LWIP_OPTTEST_FILE */
|
||||
@ -74,35 +76,35 @@
|
||||
#define LWIP_NETIF_STATUS_CALLBACK 1
|
||||
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#if LWIP_DEBUG
|
||||
|
||||
#define LWIP_DBG_MIN_LEVEL 0
|
||||
#define PPP_DEBUG LWIP_DBG_OFF
|
||||
#define MEM_DEBUG LWIP_DBG_OFF
|
||||
#define MEMP_DEBUG LWIP_DBG_OFF
|
||||
#define PBUF_DEBUG LWIP_DBG_OFF
|
||||
#define API_LIB_DEBUG LWIP_DBG_OFF
|
||||
#define API_MSG_DEBUG LWIP_DBG_OFF
|
||||
#define TCPIP_DEBUG LWIP_DBG_OFF
|
||||
#define NETIF_DEBUG LWIP_DBG_OFF
|
||||
#define SOCKETS_DEBUG LWIP_DBG_OFF
|
||||
#define DNS_DEBUG LWIP_DBG_OFF
|
||||
#define AUTOIP_DEBUG LWIP_DBG_OFF
|
||||
#define DHCP_DEBUG LWIP_DBG_OFF
|
||||
#define IP_DEBUG LWIP_DBG_OFF
|
||||
#define IP_REASS_DEBUG LWIP_DBG_OFF
|
||||
#define ICMP_DEBUG LWIP_DBG_OFF
|
||||
#define IGMP_DEBUG LWIP_DBG_OFF
|
||||
#define UDP_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_RTO_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_CWND_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_WND_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_FR_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_RST_DEBUG LWIP_DBG_OFF
|
||||
#define PPP_DEBUG LWIP_DBG_ON
|
||||
#define MEM_DEBUG LWIP_DBG_ON
|
||||
#define MEMP_DEBUG LWIP_DBG_ON
|
||||
#define PBUF_DEBUG LWIP_DBG_ON
|
||||
#define API_LIB_DEBUG LWIP_DBG_ON
|
||||
#define API_MSG_DEBUG LWIP_DBG_ON
|
||||
#define TCPIP_DEBUG LWIP_DBG_ON
|
||||
#define NETIF_DEBUG LWIP_DBG_ON
|
||||
#define SOCKETS_DEBUG LWIP_DBG_ON
|
||||
#define DNS_DEBUG LWIP_DBG_ON
|
||||
#define AUTOIP_DEBUG LWIP_DBG_ON
|
||||
#define DHCP_DEBUG LWIP_DBG_ON
|
||||
#define IP_DEBUG LWIP_DBG_ON
|
||||
#define IP_REASS_DEBUG LWIP_DBG_ON
|
||||
#define ICMP_DEBUG LWIP_DBG_ON
|
||||
#define IGMP_DEBUG LWIP_DBG_ON
|
||||
#define UDP_DEBUG LWIP_DBG_ON
|
||||
#define TCP_DEBUG LWIP_DBG_ON
|
||||
#define TCP_INPUT_DEBUG LWIP_DBG_ON
|
||||
#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
|
||||
#define TCP_RTO_DEBUG LWIP_DBG_ON
|
||||
#define TCP_CWND_DEBUG LWIP_DBG_ON
|
||||
#define TCP_WND_DEBUG LWIP_DBG_ON
|
||||
#define TCP_FR_DEBUG LWIP_DBG_ON
|
||||
#define TCP_QLEN_DEBUG LWIP_DBG_ON
|
||||
#define TCP_RST_DEBUG LWIP_DBG_ON
|
||||
#endif
|
||||
|
||||
#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT)
|
||||
@ -213,7 +215,7 @@ a lot of data that needs to be copied, this should be set high. */
|
||||
|
||||
/* ---------- ARP options ---------- */
|
||||
#define LWIP_ARP 1
|
||||
#define ARP_TABLE_SIZE 0
|
||||
#define ARP_TABLE_SIZE 10
|
||||
#define ARP_QUEUEING 1
|
||||
|
||||
|
||||
|
98
src/main.c
98
src/main.c
@ -48,18 +48,9 @@
|
||||
#include <event2/event.h>
|
||||
#include <event2/listener.h>
|
||||
|
||||
//#include "lwip/opt.h"
|
||||
//#include "lwip/debug.h"
|
||||
//#include "lwip/err.h"
|
||||
//#include "lwip/init.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include "lwip/init.h"
|
||||
//#include "lwip/dns.h"
|
||||
//#include "lwip/netif.h"
|
||||
//#include "lwip/stats.h"
|
||||
//#include "lwip/sys.h"
|
||||
//#include "lwip/tcp.h"
|
||||
|
||||
enum {
|
||||
STATE_NEW = 0,
|
||||
@ -110,39 +101,6 @@ struct ocp_sock {
|
||||
struct netif *netif;
|
||||
};
|
||||
|
||||
struct socks_auth {
|
||||
u8_t ver;
|
||||
u8_t n_methods;
|
||||
u8_t methods;
|
||||
} PACK_STRUCT_STRUCT;
|
||||
|
||||
struct socks_req {
|
||||
u8_t ver;
|
||||
u8_t cmd;
|
||||
u8_t rsv;
|
||||
u8_t atyp;
|
||||
union {
|
||||
struct {
|
||||
u32_t dst_addr;
|
||||
u16_t dst_port;
|
||||
u8_t end;
|
||||
} ipv4;
|
||||
struct {
|
||||
u8_t fqdn_len;
|
||||
u8_t fqdn_name[255]; /* variable length */
|
||||
u16_t port;
|
||||
} fqdn;
|
||||
} u;
|
||||
} PACK_STRUCT_STRUCT;
|
||||
|
||||
struct socks_reply {
|
||||
u8_t ver;
|
||||
u8_t rep;
|
||||
u8_t rsv;
|
||||
u8_t atyp;
|
||||
u32_t bnd_addr;
|
||||
u16_t bnd_port;
|
||||
} PACK_STRUCT_STRUCT;
|
||||
|
||||
static struct event_base *event_base;
|
||||
|
||||
@ -152,14 +110,10 @@ static struct ocp_sock *ocp_sock_bind_list;
|
||||
static int ocp_sock_used;
|
||||
static int ocp_sock_max;
|
||||
|
||||
/* nonstatic debug cmd option, exported in lwipopts.h */
|
||||
unsigned char debug_flags = 0;
|
||||
|
||||
static int allow_remote;
|
||||
static int tcpdump_enabled;
|
||||
static int got_sighup;
|
||||
static int got_sigusr1;
|
||||
static char *dns_domain;
|
||||
|
||||
static void start_connection(struct ocp_sock *s);
|
||||
|
||||
@ -354,10 +308,6 @@ static err_t recv_cb(void *ctx, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* SOCKS protocol
|
||||
**********************************************************************/
|
||||
|
||||
/**********************************************************************
|
||||
* Connection setup
|
||||
**********************************************************************/
|
||||
@ -640,6 +590,7 @@ static void fwd_add(const char *opt)
|
||||
}
|
||||
ip_addr_t addr;
|
||||
if (addrinfo->ai_addr->sa_family == AF_INET6) {
|
||||
IP_SET_TYPE(&addr, IPADDR_TYPE_V6);
|
||||
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) addrinfo->ai_addr;
|
||||
//addr.u_addr.ip6.zone = addr6->sin6_scope_id;
|
||||
addr.u_addr.ip6.addr[0] =
|
||||
@ -663,6 +614,7 @@ static void fwd_add(const char *opt)
|
||||
addr6->sin6_addr.s6_addr[14] << 8 |
|
||||
addr6->sin6_addr.s6_addr[15] << 0;
|
||||
} else {
|
||||
IP_SET_TYPE(&addr, IPADDR_TYPE_V4);
|
||||
struct sockaddr_in *addr4 = (struct sockaddr_in *) addrinfo->ai_addr;
|
||||
addr.u_addr.ip4.addr = addr4->sin_addr.s_addr;
|
||||
}
|
||||
@ -683,13 +635,8 @@ static void fwd_add(const char *opt)
|
||||
static struct option longopts[] = {
|
||||
{ "ip", 1, NULL, 'I' },
|
||||
{ "mtu", 1, NULL, 'M' },
|
||||
{ "dns", 1, NULL, 'd' },
|
||||
{ "domain", 1, NULL, 'o' },
|
||||
{ "localfw", 1, NULL, 'L' },
|
||||
{ "dynfw", 1, NULL, 'D' },
|
||||
{ "allow-remote", 0, NULL, 'g' },
|
||||
{ "verbose", 0, NULL, 'v' },
|
||||
{ "tcpdump", 0, NULL, 'T' },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
@ -697,12 +644,13 @@ int main(int argc, char **argv)
|
||||
{
|
||||
int opt, i, vpnfd;
|
||||
char *str;
|
||||
char *ip_str, *mtu_str, *dns_str;
|
||||
ip_addr_t ip, netmask, gw, dns;
|
||||
char *ip_str, *mtu_str;
|
||||
ip_addr_t ip;
|
||||
ip4_addr_t netmask, gw;
|
||||
struct ocp_sock *s;
|
||||
struct netif netif;
|
||||
|
||||
ip_str = mtu_str = dns_str = NULL;
|
||||
ip_str = mtu_str = NULL;
|
||||
|
||||
ocp_sock_free_list = &ocp_sock_pool[0];
|
||||
for (i = 1; i < MAX_CONN; i++)
|
||||
@ -721,21 +669,9 @@ int main(int argc, char **argv)
|
||||
ip_str = getenv("INTERNAL_IP4_ADDRESS");
|
||||
mtu_str = getenv("INTERNAL_IP4_MTU");
|
||||
|
||||
dns_domain = getenv("CISCO_DEF_DOMAIN");
|
||||
str = getenv("INTERNAL_IP4_DNS");
|
||||
if (str) {
|
||||
char *p;
|
||||
|
||||
/* this could contain many addresses; just use the first one */
|
||||
dns_str = xstrdup(str);
|
||||
p = strchr(dns_str, ' ');
|
||||
if (p)
|
||||
*p = 0;
|
||||
}
|
||||
|
||||
/* override with command line options */
|
||||
while ((opt = getopt_long(argc, argv,
|
||||
"I:M:d:o:D:k:gL:vT", longopts, NULL)) != -1) {
|
||||
"I:M:gL:", longopts, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'I':
|
||||
ip_str = optarg;
|
||||
@ -743,26 +679,12 @@ int main(int argc, char **argv)
|
||||
case 'M':
|
||||
mtu_str = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
dns_str = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
dns_domain = optarg;
|
||||
break;
|
||||
case 'g':
|
||||
allow_remote = 1;
|
||||
break;
|
||||
case 'L':
|
||||
fwd_add(optarg);
|
||||
break;
|
||||
case 'v':
|
||||
debug_flags = LWIP_DBG_ON | LWIP_DBG_TRACE |
|
||||
LWIP_DBG_STATE | LWIP_DBG_FRESH |
|
||||
LWIP_DBG_HALT;
|
||||
break;
|
||||
case 'T':
|
||||
tcpdump_enabled = 1;
|
||||
break;
|
||||
default:
|
||||
die("unknown option: %c\n", opt);
|
||||
}
|
||||
@ -787,9 +709,9 @@ int main(int argc, char **argv)
|
||||
s->netif = &netif;
|
||||
|
||||
lwip_init();
|
||||
ip_addr_set_zero(&netmask);
|
||||
ip_addr_set_zero(&gw);
|
||||
netif_add(&netif, &ip.u_addr.ip4, &netmask.u_addr.ip4, &gw.u_addr.ip4, s, init_oc_netif, ip_input);
|
||||
ip4_addr_set_zero(&netmask);
|
||||
ip4_addr_set_zero(&gw);
|
||||
netif_add(&netif, ip_2_ip4(&ip), &netmask, &gw, s, init_oc_netif, ip_input);
|
||||
netif.mtu = ocp_atoi(mtu_str);
|
||||
|
||||
netif_set_default(&netif);
|
||||
|
Loading…
x
Reference in New Issue
Block a user