|
|
|
|
||||||
| comp.protocols.tcp-ip TCP and IP network protocols. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi Ng,
i have a physical network interface with two ip-addresses bound within the same subnet. (which i did'nt expect to work btw.) eth0: 192.168.42.100 (maintenance) eth0:1 192.168.42.102 (official service point, may be transferred to another machine for hot-swap) now i create a socket SOCKET sd = socket(AF_INET, SOCK_STREAM, 0); then i connect sockaddr_in sinRemote; sinRemote.sin_family = AF_INET; sinRemote.sin_addr.s_addr = RemoteAddr; sinRemote.sin_port = Port; connect(sd, (sockaddr*)&sinRemote, sizeof(sockaddr_in)); Question: How does the ip-stack select which addres to fill in for the src ip header field? Regards, Michael |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
reppisch wrote:
> How does the ip-stack select which addres to fill in for the src ip > header field? The one with the lowest metric ? |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
In article <egvt51$g35$1@online.de>, reppisch <spam@reppisch.de> wrote:
> Hi Ng, > > i have a physical network interface with two ip-addresses bound within > the same subnet. (which i did'nt expect to work btw.) > > eth0: 192.168.42.100 (maintenance) > eth0:1 192.168.42.102 (official service point, may be transferred to > another machine for hot-swap) > > now i create a socket > > SOCKET sd = socket(AF_INET, SOCK_STREAM, 0); > > then i connect > > sockaddr_in sinRemote; > sinRemote.sin_family = AF_INET; > sinRemote.sin_addr.s_addr = RemoteAddr; > sinRemote.sin_port = Port; > connect(sd, (sockaddr*)&sinRemote, sizeof(sockaddr_in)); > > Question: > How does the ip-stack select which addres to fill in for the src ip > header field? It uses the address of the outgoing interface found in the routing table entry for the destination address. If there are multiple routing table entries with different interfaces, it may pick one arbitrarily (perhaps in round robin fashion). However, I think many stacks also give preference to real interfaces (eth0) over virtual interfaces (eth0:1). -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group *** |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Hello,
Barry Margolin a écrit : > In article <egvt51$g35$1@online.de>, reppisch <spam@reppisch.de> wrote: >> >>Question: >>How does the ip-stack select which addres to fill in for the src ip >>header field? There are some guidelines in RFC 1122 "Requirements for Internet Hosts - Communication Layers", paragraph 3.3.4.3 "Choosing a Source Address". (a) If the remote Internet address lies on one of the (sub-) nets to which the host is directly connected, a corresponding source address may be chosen, unless the corresponding interface is known to be down. (b) The route cache may be consulted, to see if there is an active route to the specified destination network through any network interface; if so, a local IP address corresponding to that interface may be chosen. (c) The table of static routes, if any (see Section 3.3.1.2) may be similarly consulted. (d) The default gateways may be consulted. If these gateways are assigned to different interfaces, the interface corresponding to the gateway with the highest preference may be chosen. > It uses the address of the outgoing interface found in the routing table > entry for the destination address. Linux TCP/IP stack gives priority to the source address specified in the route for the destination. E.g. : $ ip route list 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.1 default via 192.168.0.1 dev eth2 means that 192.168.0.1 is the default source address used to communicate with any host in the 192.168.0.0/24 subnet. This kind of route is automatically installed when you configure an interface with an IP address and subnet. Also, when an interface is configured with several addresses in different subnets, this is what makes so that the chosen source address in the one which is in the same subnet as the destination address. $ ip route list default via 192.168.0.1 dev eth2 means that the default source address used to communicate with any host via the default route is the source address used to communicate with the gateway 192.168.0.1. If no source address nor gateway is specified in the route, one of the output interface addresses is chosen. If the output interface has no address, another interface address is chosen (no kidding). > If there are multiple routing table > entries with different interfaces, it may pick one arbitrarily (perhaps > in round robin fashion). I don't think there is any round robin, because the chosen address seems to be always the same. However I am not sure about how it is chosen. > However, I think many stacks also give > preference to real interfaces (eth0) over virtual interfaces (eth0:1). This is not true for Linux, for a simple reason : the routing code doesn't know about "virtual" (alias) addresses and does not distinguish between a "primary" address and an alias address. All it knows about is addresses and "real" interfaces. You'll never see virtual interfaces in a routing table. I observed that the first configured address is the one which gets the preference. Virtual interfaces (e.g. eth0:something) are not really interfaces, they're just labels, and ifconfig displays thoses labels instead of dipslaying interface names. The primary address label is the plain interface name and the alias address labels are the virtual interface names. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Tue, 17 Oct 2006 13:20:49 +0200, Pascal Hambourg wrote:
> Virtual interfaces (e.g. eth0:something) are not really interfaces, > they're just labels, and ifconfig displays thoses labels instead of > dipslaying interface names. The primary address label is the plain > interface name and the alias address labels are the virtual interface names. And this is mainly because of legacy Linux behaviour. There were kernels (IIRC 2.0.x) where that was THE way to add additional addresses to an interface. The current behaviour is much better, the ifconfig behaviour you note above is just so old scripts don't break. Nowadays, use the 'ip' utility. It gives much better information than ifconfig. M4 -- Redundancy is a great way to introduce more single points of failure. |
|
![]() |
| Outils de la discussion | |
|
|