I am trying to use the tproxy w/ 2.6.14 kernel w the 2.0.3 patch version. I am running one of the examples(foreign-tcp-connect.c) provided with patch and test the tproxy. 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. 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) ); /* assign foreign address */ itp.op = TPROXY_ASSIGN; memcpy( &itp.v.addr.faddr, &cli_addr.sin_addr, sizeof( struct in_addr ) ); /* Tried with hardcoding foreign ip, did not work inet_aton("172.16.66.127", (struct in_addr *) &itp.v.addr.faddr); */ /*itp.v.addr.fport = htons(2000);*/ 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; } When I run the server with the above code in full and try to connect with a client it gives me the following output. ./fserver Here is the client: 172.16.66.127:41458 Here is the itp vals for faddr and fport 172.16.66.127:41458 setsockopt(SOL_IP, IP_TPROXY, TPROXY_ASSIGN): Invalid argument I am not able to figure out what the issue is here. Any help in this regards will be greatly appreciated. Thanks
participants (1)
-
Sai Bathina