Re: UDP sockets bound to ANY send answers with wrong src ip address

From: Denis Vlasenko
Date: Fri Jun 11 2004 - 07:50:31 EST


On Friday 11 June 2004 13:34, Herbert Xu wrote:
> Denis Vlasenko <vda@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> > I looked into sendmsg(). Looks like ther is no way to
> > indicate source ip.
> >
> > Shall I use some other technique?
>
> IP_PKTINFO works just as well there. Look at the ip_cmsg_send call
> in udp_sendmsg.

int udp_sendmsg(...)
{
...
ipc.addr = inet->saddr;

ipc.oif = sk->sk_bound_dev_if;
if (msg->msg_controllen) {
err = ip_cmsg_send(msg, &ipc);
if (err)
return err;
if (ipc.opt)
free = 1;
connected = 0;
}
if (!ipc.opt)
ipc.opt = inet->opt;

saddr = ipc.addr;
...

int ip_cmsg_send(struct msghdr *msg, struct ipcm_cookie *ipc)
{
...
case IP_PKTINFO:
{
struct in_pktinfo *info;
if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct in_pktinfo)))
return -EINVAL;
info = (struct in_pktinfo *)CMSG_DATA(cmsg);
ipc->oif = info->ipi_ifindex;
ipc->addr = info->ipi_spec_dst.s_addr;

manpage:
IP_PKTINFO
Pass an IP_PKTINFO ancillary message that contains a pktinfo structure that supplies some information about the
incoming packet. This only works for datagram oriented sockets.

struct in_pktinfo
{
unsigned int ipi_ifindex; /* Interface index */
struct in_addr ipi_spec_dst; /* Routing destination address */
struct in_addr ipi_addr; /* Header Destination address */
};

Hmmm... do I have to set a *routing dest address* field
to set src ip address of my UDP packet?
--
vda
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html