Linux: Raw Sockets Sent Packets Not Received Locally Under KVM -


i've been trying send udp packets using raw socket, however, sent packets not received locally. same packets received if sent remote destination. test performed under kvm. same test seems working under parallels.

the socket set with:

raw_socket = socket (af_packet, sock_raw, htons (eth_p_all));

there's receive filter attached , set promiscuous. packets received correctly. sent packets received in wireshark , analysed correctly. however, local program (e.g. nc -l -u -p ...) not receive packet. if send same packet remote destination, packet received correctly. fact wireshark receives packet suggests not dropped iptables rules (i've checked drop rules counters , there no dropped packets).

it seems if packet routed not reprocessed network stack, if makes sense.

it's supposed example code in network course, , currently, i'm losing face in front of students. hope none of them on list ;-).

would appreciate help, yuval.

a few comments code. brevity, udp checksum set 0, ip checksum calculated header. both validated wireshark (and accepted remote machine on kvm well). code parses message , sends reply on buffer received. udp_hdr , ip_hdr point corresponding headers in packet buffer (buffer), while payload points start of l7 data.

here's code: { /* process request. */ ssize_t msg_len; int max_len = sizeof (buffer) - (payload - buffer); int tmp_port; in_addr_t tmp_ip; struct ether_addr tmp_ether;

        msg_len = parse_and_send (ctx, payload, size, max_len);         if (msg_len < 0)         {            /* error */            error_print (ctx, "failed parse , construct answer.");        continue;         }         if (msg_len == 0)         {            /* no message send. */            continue;         }          /* switch sources & destinations , update payload lengths. */         tmp_port = udp_hdr->dest;         udp_hdr->dest = udp_hdr->source;         udp_hdr->source = tmp_port;         udp_hdr->len = htons (msg_len +                               (payload - (const uint8_t*) udp_hdr));         tmp_ip = ip_hdr->daddr;         compute_udp_cksum (udp_hdr);          ip_hdr->daddr = ip_hdr->saddr;     ip_hdr->saddr = tmp_ip;         ip_hdr->tot_len = htons (msg_len +                                  (payload - (const uint8_t*) ip_hdr));         compute_ip_cksum (ip_hdr);          memcpy (tmp_ether.ether_addr_octet, ether_hdr->ether_dhost,                 sizeof (tmp_ether));         memcpy (ether_hdr->ether_dhost, ether_hdr->ether_shost, eth_alen);         memcpy (ether_hdr->ether_shost, tmp_ether.ether_addr_octet,                 sizeof (tmp_ether));          if (sendto (ctx->raw_socket,                     &buffer, msg_len + (payload - buffer), 0,                     (struct sockaddr*) &ll_addr, sizeof (ll_addr)) < 0)         {            error_system (ctx, "sending packet");            error_print (ctx, "failed send packet");        continue;         }      } 

lets write down facts know:

1- told can see packets in packet capture programe (e.g wireshark)

2- told can not receive packets using netcat when send loopback interface.

3- told can receive packets when send them remote machine.

so problem either in code or local machine. have bunch of suggestions:

1- test code on machine, , send packets loopback interface , try capture them using netcat.

or

2- try send bunch of udp packets using netcat local interface , receive them using netcat instance , check if works; if worked know problem in code otherwise problem can because of local machine.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -