the port_no in struct vport of openvswitch is different from the port number? - virtualization

I modified the ovs2.6.0 and want to handle some packets.
I printk the prev_port(prev_port = nla_get_u32(a)) in do_execute_actions function. However, the prev_port sometimes is not the correct port number which the packet is forwarded to. But the TCP transmission is normal. I guess that the port number in ovs is numbered in a random way?

Related

Finding server socket's port number

I am creating a server socket as
% set serverSocket [socket -server accept 0]
sock005DBCC0
Since I am using the port number as zero, the operating system will allocate a free port to the server socket.
From the man page, I understand that we have to use -sockname with chan configure to get the port number.
-sockname
For client sockets (including the channels that get created when a
client connects to a server socket) this option returns a list of
three elements, the address, the host name and the port number for the
socket. If the host name cannot be computed, the second element is
identical to the address, the first element of the list.
% chan configure $serverSocket -sockname
0.0.0.0 0.0.0.0 65495 :: :: 65495
As you can see the above command returns six elements. What is the significance of :: here ? Is it referring global scope ?
My actual intention is to get the port number to which the socket is listening.
So, in order to get the port number, can I retrieve the last element of the list alone as shown below?
% set serverPort [lindex [chan configure $serverSocket -sockname] end]
65495
%
The reason why I'm asking this is because of the repetition of that port number in that list.
There are two sets of three elements in that list precisely because the server socket under the covers is actually two: one for IPv4 and one for IPv6. Tcl opens both since it doesn't know how clients are going to connect ahead of time (unless you use the -myaddr option when making the server option to make it so that only one protocol is possible). They could theoretically be on different ports, but that's really quite unlikely as Tcl tries to use the same port for both; your idea about taking the last item is probably fine.
If you really care, when you've got two addresses the first one will be the IPv4 address and the second will be the IPv6 address, so you can use lindex … 2 or lindex … 5 (or lindex … end) to pick exactly what you mean.
I'd probably do:
lassign [chan configure $serverSocket -sockname] serverAddress serverName serverPort
:: is the equivalent of 0.0.0.0, the unspecified address, for IPv6
(http://www.ietf.org/rfc/rfc3513.txt, page)
It looks like the port is 65495. You're getting two sets of three elements, one for ipv4, one for ipv6

TCP/IP basics, offset, reassembly

I`m writing packet generator right now. Testing it with wireshark and VM. I have an exercise on my checklist to sent 3 packets in a row:
1. TCP on 80 port, with SYN=1 and MF=1 flags.
2. TCP on 135 port, with SYN=1 and MF=1 flags.
3. TCP on 80 port, with MF = 0 and offset = 24.
I`m sending all the packets with the same ID field on IP layer.So as I understand Wireshark should try to reassemble these packets.
But will it reassemble packets from different ports?And what should we get as final result?
All I get is 3 IPv4 packets.
http://cs625124.vk.me/v625124860/10bf5/BQFUbKT7zVs.jpg
Addition: I mentioned, that if I change offset of last TCP-packet to 16, than we got a bit different kind of traffic.:
We got one HTTP or continuos packet. And here is wrong checksum. I tried to copy correct checksum to the first TCP packet and then I got RST, so i think that WireShark interpreted SYN from 1-st packet:
http://s28.postimg.org/z3w7ibhjx/image.png
So could you please explain me, was the last result correct? I would appreciate any help. Sorry if it is something basic. It`s my first expirience of writing WinForm application and using Pcap.Net library too. Thanks in advance!Sorry for links, have no reputation(
First, a TCP session is defined by the tuple:
Side A's IP address.
Side A's Port.
Side B's IP address.
Side B's Port.
If you have packets with different tuples, they will not be part of the same TCP session.
You get a RST when the server closes the session.
It is likely the server doesn't like getting SYN packets from port 21 (FTP) to its port 80 (HTTP).

Processing of a TCP packet

I am wondering what is happening between the creating a TCP packet and a [Ethernet[IP[TCP-packet]]] leaving the network adapter.
When i use for example a TCP program and want to send a single packet ( or could be more in fact TCP using byte streaming).
So i set up in any language a function called socket(...);
So my OS, refering to any documenation, creating me an interface with a specified port on which I can receive and send data over.
And if I create a TCP package (for example sendto(...), it will be send to the socket.
But what kind processes are done now [1], until my packet will leave the network adapter with an Ethernet + IP Header?
[1]: Where are the following steps happening (OS/Network adapter) and how does it exactly work?
Hope you understand me.. and please correct me if I missunderstood something wrong.

Erlang: receive multiple multicast streams on the same port

I have a multicast-based IPTV in my network.
All channels have muticast addresses like 239.0.1.*.
Streamer device sends UDP data to target port 1234.
So to receive a tv stream I do usual stuff like:
{ok, S} = gen_udp:open(1234, ....
inet:setopts(S, [{add_membership, {{239,0,1,2}, {0,0,0,0}}}]),
It works.
Now I want to subscribe to multiple channels to receive several streams simultaneously.
So I do another call:
inet:setopts(S, [{add_membership, {{239,0,1,3}, {0,0,0,0}}}]),
It works too. I see both streams in Wireshark. I can distinguish them by destination IP addresses - 239.0.1.2 and 239.0.1.3.
BUT.
In Erlang I cant figure out a channel to which incoming packet belongs, cause UDP data arrives as messages:
{udp, Socket, IP, PortNo, Packet},
where IP and PortNo is the source address (10.33.33.32 in my case) and port (49152).
So the question is - how to determine destination IP address of incoming multicast UPD packet.
Windows 7, Erlang 5.9/OTP R15B.
Thanks!
This should retrieve the destination IP from received UDP data:
{udp, Socket, IP, PortNo, Packet},
{ok, {Address, Port}} = inet:sockname(Socket),
Address will contain tuple like {239,0,1,3}.

How to bind to any available port?

I need an app that sends an UDP packet to some network server and receives the response. The server replies to the same port number where request came from, so I first need to bind() my socket to any UDP port number.
Hardcoding the UDP port number is a bad idea, as it might be used by any other application running on the same PC.
Is there a way to bind an UDP socket to any port available? IMO it should be an effective way to quickly obtain a free port #, which is used by e.g. accept() function.
If no, then what's the best strategy to try binding and check for WSAEADDRINUSE/EADDRINUSE status: try the ports sequentially starting from from 1025, or 1025+rand(), or some other?
Another option is to specify port 0 to bind(). That will allow you to bind to a specific IP address (in case you have multiple installed) while still binding to a random port. If you need to know which port was picked, you can use getsockname() after the binding has been performed.
Call sendto without calling bind first, the socket will be bound automatically (to a free port).
I must be missing something, why don't you use the udp socket to send back data?
Start with sendto and then use recvfrom function to read incoming data also you get as a bonus the address from which the data was sent, right there for you to send a response back.