PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Noms de domaine > comp.protocols.tcp-ip > how ist the src Address determined in connect with two interfaces,same subnet?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.protocols.tcp-ip TCP and IP network protocols.

how ist the src Address determined in connect with two interfaces,same subnet?

Réponse
 
LinkBack Outils de la discussion
Vieux 16/10/2006, 13h15   #1
reppisch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut how ist the src Address determined in connect with two interfaces,same subnet?

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
  Réponse avec citation
Vieux 16/10/2006, 19h55   #2
hasenhei
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how ist the src Address determined in connect with two interfaces, same subnet?

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 ?

  Réponse avec citation
Vieux 17/10/2006, 02h10   #3
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how ist the src Address determined in connect with two interfaces, same subnet?

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 ***
  Réponse avec citation
Vieux 17/10/2006, 12h20   #4
Pascal Hambourg
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how ist the src Address determined in connect with two interfaces,same subnet?

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.
  Réponse avec citation
Vieux 18/10/2006, 22h57   #5
Martijn Lievaart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how ist the src Address determined in connect with two interfaces, same subnet?

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.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h47.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10798 seconds with 13 queries