Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,10 @@ static int parse_xml_config(struct tunnel *tunnel, const char *buffer)
log_warn("No gateway address, using interface for routing\n");

if (tunnel->config->tun) {
tunnel->ipv4.ip_addr.s_addr = inet_addr(gateway);
if (!gateway)
tunnel->ipv4.ip_addr.s_addr = inet_addr("192.0.2.2");
else
tunnel->ipv4.ip_addr.s_addr = inet_addr(gateway);
tunnel->ipv4.peer_addr.s_addr = inet_addr("192.0.2.1");
}

Expand Down
26 changes: 14 additions & 12 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,8 @@ int ipcp_option_send(struct tunnel *tunnel, int id, int code,
int ret = -1;

if (optlist && optlist->head) {
uint8_t *packet = (uint8_t *)optlist->head;
struct ipcp_header *header = ((struct ipcp_header *)packet) - 1;
uint8_t *ppacket = (uint8_t *)optlist->head;
struct ipcp_header *header = ((struct ipcp_header *)ppacket) - 1;
unsigned short *ppp_type = ((unsigned short *)header) - 1;
const size_t hdrlen = sizeof(struct ipcp_header) + sizeof(uint16_t);
const int len = conf_option_length(optlist);
Expand Down Expand Up @@ -799,7 +799,7 @@ int ipcp_option_send(struct tunnel *tunnel, int id, int code,

int ipcp_packet(struct tunnel *tunnel, void *packet, int len)
{
int ret = 0;
int ret = -1;
struct ipcp_header *header = packet;

log_debug("packet %s\n", ipcp_code_name[header->code]);
Expand Down Expand Up @@ -846,7 +846,6 @@ int ipcp_packet(struct tunnel *tunnel, void *packet, int len)
co = (struct conf_option *)((uint8_t *)co + co->length);
}
if (header->code == IPCP_CONF_REQUEST) {
int ret = -1;

ret = ipcp_option_send(tunnel, header->id, IPCP_CONF_ACK,
&ack, 0);
Expand Down Expand Up @@ -935,7 +934,6 @@ int ipcp_packet(struct tunnel *tunnel, void *packet, int len)
}

tun_ifup(tunnel->tun_iface, ip_address, peer_address);
ipv4_set_tunnel_routes(tunnel);
break;
}
case IPCP_CONF_NAK: {
Expand Down Expand Up @@ -1054,6 +1052,7 @@ int ipcp_packet(struct tunnel *tunnel, void *packet, int len)
errno, strerror(errno));
exit(EXIT_FAILURE);
}
conf_option_free(&request);
} while (0);
break;
}
Expand Down Expand Up @@ -1233,7 +1232,7 @@ static void *pppd_write(void *arg)

while (1) {
struct ppp_packet *packet;
ssize_t hdlc_bufsize, len, n, written;
ssize_t len, n, written;
uint8_t *hdlc_buffer;

// This waits until a packet has arrived from the gateway
Expand All @@ -1242,13 +1241,15 @@ static void *pppd_write(void *arg)
if (tunnel->config->tun) {
void *pkt_type = pkt_data(packet);

hdlc_bufsize = len = packet->len;
len = packet->len - 2;
switch (ntohs(*(uint16_t *)pkt_type)) {
case PPP_LCP:
lcp_packet(tunnel, pkt_data(packet) + 2, len - 2);
lcp_packet(tunnel, pkt_data(packet) + 2, len);
free(packet);
continue;
case PPP_IPCP:
ipcp_packet(tunnel, pkt_data(packet) + 2, len - 2);
ipcp_packet(tunnel, pkt_data(packet) + 2, len);
free(packet);
continue;
case PPP_IP:
case PPP_IPV6:
Expand All @@ -1257,15 +1258,16 @@ static void *pppd_write(void *arg)
goto out_free_packet;
}

hdlc_buffer = malloc(packet->len);
hdlc_buffer = malloc(len);
if (hdlc_buffer == NULL) {
log_error("malloc: %s\n", strerror(errno));
break;
}

memcpy(hdlc_buffer, pkt_data(packet) + 2, packet->len - 2);
memcpy(hdlc_buffer, pkt_data(packet) + 2, len);
} else {
hdlc_bufsize = estimated_encoded_size(packet->len);
size_t hdlc_bufsize = estimated_encoded_size(packet->len);

hdlc_buffer = malloc(hdlc_bufsize);
if (hdlc_buffer == NULL) {
log_error("malloc: %s\n", strerror(errno));
Expand Down