- strip off the MAC adresses of an ethernet frame
-*/
-void strip_mac_addresses(vpn_packet_t *p)
-{
- unsigned char tmp[MAXSIZE];
-cp
- memcpy(tmp, p->data, p->len);
- p->len -= 12;
- memcpy(p->data, &tmp[12], p->len);
-cp
-}
-
-/*
- reassemble MAC addresses
-*/
-void add_mac_addresses(vpn_packet_t *p)
-{
- unsigned char tmp[MAXSIZE];
-cp
- memcpy(&tmp[12], p->data, p->len);
- p->len += 12;
- tmp[0] = tmp[6] = 0xfe;
- tmp[1] = tmp[7] = 0xfd;
- *((ip_t*)(&tmp[2])) = (ip_t)(htonl(myself->vpn_ip));
- *((ip_t*)(&tmp[8])) = *((ip_t*)(&tmp[26]));
- memcpy(p->data, &tmp[0], p->len);
-cp
-}
-
-int xsend(conn_list_t *cl, void *packet)
-{
- real_packet_t rp;
-cp
- do_encrypt((vpn_packet_t*)packet, &rp, cl->key);
- rp.from = htonl(myself->vpn_ip);
- rp.data.len = htons(rp.data.len);
- rp.len = htons(rp.len);
-
- if(debug_lvl > 3)
- syslog(LOG_ERR, _("Sending packet of %d bytes to %s (%s)"),
- ntohs(rp.len), cl->name, cl->hostname);
-
- total_socket_out += ntohs(rp.len);
-
- cl->want_ping = 1;
-
- if((cl->flags | myself->flags) & TCPONLY)
- return send_tcppacket(cl, (void*)&rp, ntohs(rp.len));
-
- if((send(cl->socket, (char*)&rp, ntohs(rp.len), 0)) < 0)
- {
- syslog(LOG_ERR, _("Error sending packet to %s (%s): %m"),
- cl->name, cl->hostname);
- return -1;
- }
-cp
- return 0;
-}
-
-int xrecv(conn_list_t *cl, void *packet)
-{
- vpn_packet_t vp;
- int lenin;
-cp
- do_decrypt((real_packet_t*)packet, &vp, cl->key);
- add_mac_addresses(&vp);
-
- if(debug_lvl > 3)
- syslog(LOG_ERR, _("Receiving packet of %d bytes from %s (%s)"),
- ((real_packet_t*)packet)->len, cl->name, cl->hostname);
-
- if((lenin = write(tap_fd, &vp, vp.len + sizeof(vp.len))) < 0)
- syslog(LOG_ERR, _("Can't write to tap device: %m"));
- else
- total_tap_out += lenin;
-
- cl->want_ping = 0;
- cl->last_ping_time = time(NULL);
-cp
- return 0;
-}
-
-/*
- add the given packet of size s to the
- queue q, be it the send or receive queue