[tproxy] Invalid Arguement for setsockopt
Sai Bathina
sai.bathina at gmail.com
Wed Jan 4 22:42:50 CET 2006
Thanks for the reply.
Well the piece of code was testing for the implementation of smtp
proxy. So the server has to act as a tproxy.
I had resolved the issue. Actually my server is running in the bridge
mode and I traced the issue to the config parameter:
CONFIG_IP_NF_NAT_NRES
if this is set then I am having this problem so I :
# CONFIG_IP_NF_NAT_NRES is not set
and it worked fine. I am not sure why it resolved but it did. Will it
affect something else...I am not sure about that.
Thanks
Sai
On 12/22/05, KOVACS Krisztian <hidden at sch.bme.hu> wrote:
>
> Hi,
>
> On 2005. December 20. 00.08, Sai Bathina wrote:
> > I am seeing that I am getting an Invalid Arguement for setsockopt for
> > TPROXY_ASSIGN.
> > I have tried this compiling tproxy into the kernel as well as loading
> > them as modules.
>
> First of all, sorry for the delayed answer.
>
> Obviously, compiling into the kernel and loading as a module should
> give exactly the same results.
>
> > This is the code snippet:
> >
> > sock = socket(AF_INET, SOCK_STREAM, 0);
> > if (sock == -1)
> > {
> > perror("socket");
> > return -1;
> > }
> >
> > /* check tproxy version*/
> > itp.op = TPROXY_VERSION;
> > itp.v.version = 0x02000000;
> > if (setsockopt(sock, SOL_IP, IP_TPROXY, &itp, sizeof(itp)) == -1)
> > {
> > perror("setsockopt(SOL_IP, IP_TPROXY, TPROXY_VERSION)");
> > return -1;
> > }
> >
> > /* bind to local address */
> > sin.sin_family = AF_INET;
> > sin.sin_addr.s_addr = INADDR_ANY;
> > //inet_aton(argv[1], &sin.sin_addr);
> > sin.sin_port = htons(9999);
> >
> > if (bind(sock, (struct sockaddr *) &sin, sizeof(sin)) == -1)
> > {
> > perror("bind");
> > return -1;
> > }
> >
> > listen(sock, 5);
> > clilen = sizeof(cli_addr);
> > newsockfd = accept(sock,(struct sockaddr *) &cli_addr,&clilen);
> > if (newsockfd < 0)
> > error("ERROR on accept");
> >
> > printf("Here is the client:
> > %s:%i\n",inet_ntoa(cli_addr.sin_addr.s_addr),
> > ntohs(cli_addr.sin_port) );
>
> Ok, no problems up to this point. However, the next few lines are
> somewhat problematic.
>
> > /* assign foreign address */
> > itp.op = TPROXY_ASSIGN;
> >
> > memcpy( &itp.v.addr.faddr, &cli_addr.sin_addr, sizeof( struct
> > in_addr ) );
> >
> > itp.v.addr.fport = cli_addr.sin_port;
> >
> > printf("Here is the itp vals for faddr and fport
> > %s:%i\n",inet_ntoa(itp.v.addr.faddr), ntohs(itp.v.addr.fport) );
> >
> > if (setsockopt(sock, SOL_IP, IP_TPROXY, &itp, sizeof(itp)) == -1)
> > {
> > perror("setsockopt(SOL_IP, IP_TPROXY, TPROXY_ASSIGN)");
> > return -1;
> > }
>
> Once you've accept()-ed the connection and have a socket, you cannot
> do any assignments on the socket because it has the same local endpoint
> (IP:port) as the listener socket. By the way, I don't really get what
> you're trying to do, so I could probably help you more if you told us
> what this piece of the program is supposed to achieve.
>
> --
> KOVACS Krisztian
>
More information about the tproxy
mailing list