-/*
- read, encrypt and send data that is
- available through the ethertap device
-*/
-void handle_tap_input(void)
-{
- vpn_packet_t vp;
- ip_t from, to;
- int ether_type, lenin;
-cp
- memset(&vp, 0, sizeof(vp));
- if((lenin = read(tap_fd, &vp, MTU)) <= 0)
- {
- syslog(LOG_ERR, "Error while reading from tapdevice: %m");
- return;
- }
-
- total_tap_in += lenin;
-
- ether_type = ntohs(*((unsigned short*)(&vp.data[12])));
- if(ether_type != 0x0800)
- {
- if(debug_lvl > 0)
- syslog(LOG_INFO, "Non-IP ethernet frame %04x from " MAC_ADDR_S,
- ether_type, MAC_ADDR_V(vp.data[6]));
- return;
- }
-
- if(lenin < 32)
- {
- if(debug_lvl > 0)
- syslog(LOG_INFO, "Dropping short packet");
- return;
- }
-
- from = ntohl(*((unsigned long*)(&vp.data[26])));
- to = ntohl(*((unsigned long*)(&vp.data[30])));
-
- if(debug_lvl > 3)
- syslog(LOG_DEBUG, "An IP packet (%04x) for " IP_ADDR_S " from " IP_ADDR_S,
- ether_type, IP_ADDR_V(to), IP_ADDR_V(from));
- if(debug_lvl > 4)
- syslog(LOG_DEBUG, MAC_ADDR_S " to " MAC_ADDR_S,
- MAC_ADDR_V(vp.data[0]), MAC_ADDR_V(vp.data[6]));
-
- vp.len = (length_t)lenin - 2;
-
- strip_mac_addresses(&vp);
-
- send_packet(to, &vp);
-cp
-}