netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* How to compile tcp fast open client app with kernel tfo client support ?
@ 2012-11-09 18:05 Vincent Li
  2012-11-09 18:23 ` Vijay Subramanian
  0 siblings, 1 reply; 10+ messages in thread
From: Vincent Li @ 2012-11-09 18:05 UTC (permalink / raw)
  To: netdev

[-- Attachment #1: Type: text/plain, Size: 1351 bytes --]

Hi,

this is sort of off toptic, sorry for the noise.

I am running ubuntu 10.0.4 with kernel 3.6.0 with tfo client support,
then I have simple client code that i want to use to test tcp fast
open, here is part of the code:

  int sent = 0;
  while(sent < strlen(get))
  {
    tmpres = sendto(sock, get+sent, strlen(get)-sent, MSG_FASTOPEN,
(struct sockaddr *)remote, sizeof(struct sockaddr));
    if(tmpres == -1){
      perror("Can't send query");
      exit(1);
    }
    sent += tmpres;
  }

when i compile it, as gcc -o htmlgettfo htmlgettfo.c, I got:

htmlgettfo.c: In function 'get_page_thread':
htmlgettfo.c:109: error: 'MSG_FASTOPEN' undeclared (first use in this function)
htmlgettfo.c:109: error: (Each undeclared identifier is reported only once
htmlgettfo.c:109: error: for each function it appears in.)

I have the 3.6.0 kernel header file package installed
/usr/src/linux-headers-3.6.0-custom, the user space include file
/usr/include/linux is original one coming with 10.0.4 distro kernel

I am suspecting I don't have proper linux header file that has
MSG_FASTOPEN declared in user space. can anyone shed a light on how to
get MSG_FASTOPEN supported and compiled in client code properly?

I am attempting to use the test client code to test one of our load
balancer and see how it responds.


I attached my test code

Thanks

Vincent

[-- Attachment #2: htmlgettfo.c.txt --]
[-- Type: text/plain, Size: 4179 bytes --]

#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <netdb.h>
#include <string.h>

#include <pthread.h>
#include <unistd.h>
#include <linux-3.6.0/socket.h>

#define MAX_HOST_PAGE 2

struct host_page {
    char *host;
    char *page;
} hp[MAX_HOST_PAGE];

int tcp_connect(char *host);
char *get_ip(char *host);
char *build_get_query(char *host, char *page);
int *get_page_thread(struct host_page *hp);
void usage();

#define HOST "host.example.com"
#define PAGE "/"
#define PORT 80
#define USERAGENT "HTMLGET 1.0"

int main(int argc, char **argv)
{
 
  struct host_page *hpptr; 
 
  if(argc == 1){
    usage();
    exit(2);
  }  
  hp[0].host = argv[1];
  fprintf(stderr, "hp->host:\n%s\n", hp[0].host);
  if(argc > 2){
    hp[0].page = argv[2];
    fprintf(stderr, "host->page:\n%s\n", hp[0].page);
  }else{
    hp[0].page = PAGE;
  }

 hpptr = &hp[0];

    if(get_page_thread(hpptr)){
      perror("Can't get page");
      exit(2);
    }
  
}

void usage()
{
  fprintf(stderr, "USAGE: htmlget host [page]\n\
\thost: the website hostname. ex: \n\
\tpage: the page to retrieve. ex: index.html, default: /\n");
}

int *get_page_thread(struct host_page *hp){


  struct sockaddr_in *remote;
  int sock;
  int tmpres;
  char *ip;
  char *host;
  char *page;

  host=hp->host;
  page=hp->page;

  char *get;
  char buf[BUFSIZ+1];


  if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
    perror("Can't create TCP socket");
    return 0;
  }

  ip = get_ip(host);
  fprintf(stderr, "IP is %s\n", ip);
  remote = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in *));
  remote->sin_family = AF_INET;
  tmpres = inet_pton(AF_INET, ip, (void *)(&(remote->sin_addr.s_addr)));
  if( tmpres < 0)
  {
    perror("Can't set remote->sin_addr.s_addr");
    return 0;
  }else if(tmpres == 0)
  {
    fprintf(stderr, "%s is not a valid IP address\n", ip);
    return 0;
  }
  remote->sin_port = htons(PORT);

  get = build_get_query(host, page);
  fprintf(stderr, "Query is:\n<<START>>\n%s<<END>>\n", get);

  //Send the query to the server
  int sent = 0;
  while(sent < strlen(get))
  {
    tmpres = sendto(sock, get+sent, strlen(get)-sent, MSG_FASTOPEN, (struct sockaddr *)remote, sizeof(struct sockaddr));
    if(tmpres == -1){
      perror("Can't send query");
      exit(1);
    }
    sent += tmpres;
  }
  //now it is time to receive the page
  memset(buf, 0, sizeof(buf));
  int htmlstart = 0;
  char * htmlcontent;
  while((tmpres = recv(sock, buf, BUFSIZ, 0)) > 0){
    if(htmlstart == 0)
    {
      /* Under certain conditions this will not work.
      * If the \r\n\r\n part is splitted into two messages
      * it will fail to detect the beginning of HTML content
      */
      htmlcontent = strstr(buf, "\r\n\r\n");
      if(htmlcontent != NULL){
        htmlstart = 1;
        htmlcontent += 4;
      }
    }else{
      htmlcontent = buf;
    }
    if(htmlstart){
     /* fprintf(stdout, htmlcontent); */
      fprintf(stdout, "%s", htmlcontent);
    }

    memset(buf, 0, tmpres);
  }
  if(tmpres < 0)
  {
    perror("Error receiving data");
  }
  free(get);
  free(remote);
  free(ip);
  close(sock);
  return 0;

}



char *get_ip(char *host)
{
  struct hostent *hent;
  int iplen = 15; //XXX.XXX.XXX.XXX
  char *ip = (char *)malloc(iplen+1);
  memset(ip, 0, iplen+1);
  if((hent = gethostbyname(host)) == NULL)
  {
    herror("Can't get IP");
    exit(1);
  }
  if(inet_ntop(AF_INET, (void *)hent->h_addr_list[0], ip, iplen) == NULL)
  {
    perror("Can't resolve host");
    exit(1);
  }
  return ip;
}

char *build_get_query(char *host, char *page)
{
  char *query;
  char *getpage = page;
  char *tpl = "GET /%s HTTP/1.0\r\nHost: %s\r\nUser-Agent: %s\r\n\r\n";
/*char *tpl = "GET /%s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\nConnection: close\r\n\r\n"; */
  if(getpage[0] == '/'){
    getpage = getpage + 1;
    fprintf(stderr,"Removing leading \"/\", converting %s to %s\n", page, getpage);
  }
  // -5 is to consider the %s %s %s in tpl and the ending \0
  query = (char *)malloc(strlen(host)+strlen(getpage)+strlen(USERAGENT)+strlen(tpl)-5);
  sprintf(query, tpl, getpage, host, USERAGENT);
  return query;
}


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to compile tcp fast open client app with kernel tfo client support ?
  2012-11-09 18:05 How to compile tcp fast open client app with kernel tfo client support ? Vincent Li
@ 2012-11-09 18:23 ` Vijay Subramanian
  2012-11-09 18:47   ` Vincent Li
  0 siblings, 1 reply; 10+ messages in thread
From: Vijay Subramanian @ 2012-11-09 18:23 UTC (permalink / raw)
  To: Vincent Li; +Cc: netdev

> htmlgettfo.c: In function 'get_page_thread':
> htmlgettfo.c:109: error: 'MSG_FASTOPEN' undeclared (first use in this function)
> htmlgettfo.c:109: error: (Each undeclared identifier is reported only once
> htmlgettfo.c:109: error: for each function it appears in.)
>
> I have the 3.6.0 kernel header file package installed
> /usr/src/linux-headers-3.6.0-custom, the user space include file
> /usr/include/linux is original one coming with 10.0.4 distro kernel
>
> I am suspecting I don't have proper linux header file that has
> MSG_FASTOPEN declared in user space. can anyone shed a light on how to
> get MSG_FASTOPEN supported and compiled in client code properly?
>

Vincent ,
You can try adding the following to the client code.

#define MSG_FASTOPEN    0x20000000

This is missing still from user space header files I presume.

Vijay

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to compile tcp fast open client app with kernel tfo client support ?
  2012-11-09 18:23 ` Vijay Subramanian
@ 2012-11-09 18:47   ` Vincent Li
  2012-11-09 18:53     ` Yuchung Cheng
  0 siblings, 1 reply; 10+ messages in thread
From: Vincent Li @ 2012-11-09 18:47 UTC (permalink / raw)
  To: Vijay Subramanian; +Cc: netdev

On Fri, Nov 9, 2012 at 10:23 AM, Vijay Subramanian
<subramanian.vijay@gmail.com> wrote:
>> htmlgettfo.c: In function 'get_page_thread':
>> htmlgettfo.c:109: error: 'MSG_FASTOPEN' undeclared (first use in this function)
>> htmlgettfo.c:109: error: (Each undeclared identifier is reported only once
>> htmlgettfo.c:109: error: for each function it appears in.)
>>
>> I have the 3.6.0 kernel header file package installed
>> /usr/src/linux-headers-3.6.0-custom, the user space include file
>> /usr/include/linux is original one coming with 10.0.4 distro kernel
>>
>> I am suspecting I don't have proper linux header file that has
>> MSG_FASTOPEN declared in user space. can anyone shed a light on how to
>> get MSG_FASTOPEN supported and compiled in client code properly?
>>
>
> Vincent ,
> You can try adding the following to the client code.
>
> #define MSG_FASTOPEN    0x20000000
>
> This is missing still from user space header files I presume.
>
> Vijay

Thanks Vijay, that did it. and the load banlancer doesn't recognize
the option, but traffic pass through ok. the data is sent through the
final ack of 3WHS from linux.

Vincent

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to compile tcp fast open client app with kernel tfo client support ?
  2012-11-09 18:47   ` Vincent Li
@ 2012-11-09 18:53     ` Yuchung Cheng
  2012-11-09 20:17       ` Vincent Li
  0 siblings, 1 reply; 10+ messages in thread
From: Yuchung Cheng @ 2012-11-09 18:53 UTC (permalink / raw)
  To: Vincent Li; +Cc: Vijay Subramanian, netdev

On Fri, Nov 9, 2012 at 1:47 PM, Vincent Li <vincent.mc.li@gmail.com> wrote:
> On Fri, Nov 9, 2012 at 10:23 AM, Vijay Subramanian
> <subramanian.vijay@gmail.com> wrote:
>>> htmlgettfo.c: In function 'get_page_thread':
>>> htmlgettfo.c:109: error: 'MSG_FASTOPEN' undeclared (first use in this function)
>>> htmlgettfo.c:109: error: (Each undeclared identifier is reported only once
>>> htmlgettfo.c:109: error: for each function it appears in.)
>>>
>>> I have the 3.6.0 kernel header file package installed
>>> /usr/src/linux-headers-3.6.0-custom, the user space include file
>>> /usr/include/linux is original one coming with 10.0.4 distro kernel
>>>
>>> I am suspecting I don't have proper linux header file that has
>>> MSG_FASTOPEN declared in user space. can anyone shed a light on how to
>>> get MSG_FASTOPEN supported and compiled in client code properly?
>>>
>>
>> Vincent ,
>> You can try adding the following to the client code.
>>
>> #define MSG_FASTOPEN    0x20000000
>>
>> This is missing still from user space header files I presume.
>>
>> Vijay
>
> Thanks Vijay, that did it. and the load banlancer doesn't recognize
> the option, but traffic pass through ok. the data is sent through the
> final ack of 3WHS from linux.
Hi Vincent,

Note that MSG_FASTOPEN flag should be used only once. Subsequent
sendto(MSG_FASTOPEN) == connect() on connected sockets. You can verify
if the fast open is successful by checking a bit in TCP_INFO.
http://patchwork.o zlabs.org/patch/192883/ if you are running a fresh
netdev build.

I'll submit a patch to update the man page on MSG_FASTOPEN too.

Yuchung


>
> Vincent
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to compile tcp fast open client app with kernel tfo client support ?
  2012-11-09 18:53     ` Yuchung Cheng
@ 2012-11-09 20:17       ` Vincent Li
  2012-11-09 20:27         ` Eric Dumazet
  0 siblings, 1 reply; 10+ messages in thread
From: Vincent Li @ 2012-11-09 20:17 UTC (permalink / raw)
  To: Yuchung Cheng; +Cc: Vijay Subramanian, netdev

> Hi Vincent,
>
> Note that MSG_FASTOPEN flag should be used only once. Subsequent
> sendto(MSG_FASTOPEN) == connect() on connected sockets. You can verify
> if the fast open is successful by checking a bit in TCP_INFO.
> http://patchwork.o zlabs.org/patch/192883/ if you are running a fresh
> netdev build.
>
> I'll submit a patch to update the man page on MSG_FASTOPEN too.
>
> Yuchung
>

I have tried to run fresh build net-next, for some reason the build
stops ssh service from starting up, tried 3.7.0-rc4 too, same issue. I
don't know if it is new kernel bug or ubuntu upstart bug, but that is
another issue.

I will study the tcp fast open more, thanks.

Vincent

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to compile tcp fast open client app with kernel tfo client support ?
  2012-11-09 20:17       ` Vincent Li
@ 2012-11-09 20:27         ` Eric Dumazet
  2012-11-09 20:54           ` Vijay Subramanian
  0 siblings, 1 reply; 10+ messages in thread
From: Eric Dumazet @ 2012-11-09 20:27 UTC (permalink / raw)
  To: Vincent Li; +Cc: Yuchung Cheng, Vijay Subramanian, netdev

On Fri, 2012-11-09 at 12:17 -0800, Vincent Li wrote:

> I have tried to run fresh build net-next, for some reason the build
> stops ssh service from starting up, tried 3.7.0-rc4 too, same issue. I
> don't know if it is new kernel bug or ubuntu upstart bug, but that is
> another issue.
> 

Not sure Ubuntu 10.04 binaries can run a 3.7 kernel.

Some bug fixes in kernel need bug fixes in userland.

You could try a bisection ?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to compile tcp fast open client app with kernel tfo client support ?
  2012-11-09 20:27         ` Eric Dumazet
@ 2012-11-09 20:54           ` Vijay Subramanian
  2012-11-09 21:09             ` Vincent Li
  2012-11-13  0:33             ` Vincent Li
  0 siblings, 2 replies; 10+ messages in thread
From: Vijay Subramanian @ 2012-11-09 20:54 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Vincent Li, Yuchung Cheng, netdev

On 9 November 2012 12:27, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> On Fri, 2012-11-09 at 12:17 -0800, Vincent Li wrote:
>
>> I have tried to run fresh build net-next, for some reason the build
>> stops ssh service from starting up, tried 3.7.0-rc4 too, same issue. I
>> don't know if it is new kernel bug or ubuntu upstart bug, but that is
>> another issue.
>>
>
> Not sure Ubuntu 10.04 binaries can run a 3.7 kernel.
>
> Some bug fixes in kernel need bug fixes in userland.
>
> You could try a bisection ?
>
 I saw the same issue with Ubuntu starting around 3.7.0-rc1 but 3.6
was fine if I recall. (I did a partial bisection but was not sure it
was a kernel issue)
 sshd would not start up on boot and I 'fixed' it by adding the
following in /etc/rc.local since I assumed it was a userspace issue.

if [ ! -d /var/run/sshd ]; then
   mkdir /var/run/sshd
   chmod 0755 /var/run/sshd
fi
/usr/sbin/sshd


Thanks,
Vijay

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to compile tcp fast open client app with kernel tfo client support ?
  2012-11-09 20:54           ` Vijay Subramanian
@ 2012-11-09 21:09             ` Vincent Li
  2012-11-13  0:33             ` Vincent Li
  1 sibling, 0 replies; 10+ messages in thread
From: Vincent Li @ 2012-11-09 21:09 UTC (permalink / raw)
  To: Vijay Subramanian; +Cc: Eric Dumazet, Yuchung Cheng, netdev

On Fri, Nov 9, 2012 at 12:54 PM, Vijay Subramanian
<subramanian.vijay@gmail.com> wrote:
> On 9 November 2012 12:27, Eric Dumazet <eric.dumazet@gmail.com> wrote:
>> On Fri, 2012-11-09 at 12:17 -0800, Vincent Li wrote:
>>
>>> I have tried to run fresh build net-next, for some reason the build
>>> stops ssh service from starting up, tried 3.7.0-rc4 too, same issue. I
>>> don't know if it is new kernel bug or ubuntu upstart bug, but that is
>>> another issue.
>>>
>>
>> Not sure Ubuntu 10.04 binaries can run a 3.7 kernel.
>>
>> Some bug fixes in kernel need bug fixes in userland.
>>
>> You could try a bisection ?
>>
>  I saw the same issue with Ubuntu starting around 3.7.0-rc1 but 3.6
> was fine if I recall. (I did a partial bisection but was not sure it
> was a kernel issue)
>  sshd would not start up on boot and I 'fixed' it by adding the
> following in /etc/rc.local since I assumed it was a userspace issue.
>
> if [ ! -d /var/run/sshd ]; then
>    mkdir /var/run/sshd
>    chmod 0755 /var/run/sshd
> fi
> /usr/sbin/sshd
>
>
> Thanks,
> Vijay

thanks again, you "fixed" my other issue :-)

Vincent

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to compile tcp fast open client app with kernel tfo client support ?
  2012-11-09 20:54           ` Vijay Subramanian
  2012-11-09 21:09             ` Vincent Li
@ 2012-11-13  0:33             ` Vincent Li
  2012-11-13  1:13               ` Vijay Subramanian
  1 sibling, 1 reply; 10+ messages in thread
From: Vincent Li @ 2012-11-13  0:33 UTC (permalink / raw)
  To: Vijay Subramanian; +Cc: Eric Dumazet, Yuchung Cheng, netdev

On Fri, Nov 9, 2012 at 12:54 PM, Vijay Subramanian
<subramanian.vijay@gmail.com> wrote:
> On 9 November 2012 12:27, Eric Dumazet <eric.dumazet@gmail.com> wrote:
>> On Fri, 2012-11-09 at 12:17 -0800, Vincent Li wrote:
>>
>>> I have tried to run fresh build net-next, for some reason the build
>>> stops ssh service from starting up, tried 3.7.0-rc4 too, same issue. I
>>> don't know if it is new kernel bug or ubuntu upstart bug, but that is
>>> another issue.
>>>
>>
>> Not sure Ubuntu 10.04 binaries can run a 3.7 kernel.
>>
>> Some bug fixes in kernel need bug fixes in userland.
>>
>> You could try a bisection ?
>>
>  I saw the same issue with Ubuntu starting around 3.7.0-rc1 but 3.6
> was fine if I recall. (I did a partial bisection but was not sure it
> was a kernel issue)
>  sshd would not start up on boot and I 'fixed' it by adding the
> following in /etc/rc.local since I assumed it was a userspace issue.
>
> if [ ! -d /var/run/sshd ]; then
>    mkdir /var/run/sshd
>    chmod 0755 /var/run/sshd
> fi
> /usr/sbin/sshd
>
>
> Thanks,
> Vijay

Hi Vijay,

just FYI, I filed a bug report in ubuntu and it appears to be a kernel
commit breaks the user space code that still using deprecated kernel
knobs oom_adj.

https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1077248

commit 01dc52ebdf472f77cca623ca693ca24cfc0f1bbe
Author: Davidlohr Bueso <dave@gnu.org>
Date: Mon Oct 8 16:29:30 2012 -0700

    oom: remove deprecated oom_adj

    The deprecated /proc/<pid>/oom_adj is scheduled for removal this month.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to compile tcp fast open client app with kernel tfo client support ?
  2012-11-13  0:33             ` Vincent Li
@ 2012-11-13  1:13               ` Vijay Subramanian
  0 siblings, 0 replies; 10+ messages in thread
From: Vijay Subramanian @ 2012-11-13  1:13 UTC (permalink / raw)
  To: Vincent Li; +Cc: Eric Dumazet, Yuchung Cheng, netdev

> Hi Vijay,
>
> just FYI, I filed a bug report in ubuntu and it appears to be a kernel
> commit breaks the user space code that still using deprecated kernel
> knobs oom_adj.
>

Vincent,
Thanks for following up and finding the exact cause!!

Vijay

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-11-13  1:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-09 18:05 How to compile tcp fast open client app with kernel tfo client support ? Vincent Li
2012-11-09 18:23 ` Vijay Subramanian
2012-11-09 18:47   ` Vincent Li
2012-11-09 18:53     ` Yuchung Cheng
2012-11-09 20:17       ` Vincent Li
2012-11-09 20:27         ` Eric Dumazet
2012-11-09 20:54           ` Vijay Subramanian
2012-11-09 21:09             ` Vincent Li
2012-11-13  0:33             ` Vincent Li
2012-11-13  1:13               ` Vijay Subramanian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).