Skip to contentSkip to conversation

Latest lksctp-dev tree broke sctp_sendmsg()?

DISCUSSION Horacio Sanson 4 participants 11 messages Apr 21, 2008 – Apr 24, 2008 SCTP protocol

lore
Share & tools
lore
#0 lore raw

I have a small echo server/client program for testing. It works in linux kernel 2.6.22-14 (Ubuntu) but using the latest lksctp-dev tree (from git) I get "invalid parameter" errors when calling sctp_sendmsg().

Any directions are appreciated:

Horacio

###############

# server code
###############
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#define MAXLINE     255
#define LISTENQ     1024
#define SERV_PORT   9879
#define BUFFSIZE    8192

int main(int arvc, char **argv)

{
    int sock_fd, msg_flags, ret;
    char readbuf[BUFFSIZE];

    struct sockaddr_in servaddr, cliaddr;
    struct sctp_sndrcvinfo sri;
    struct sctp_event_subscribe evnts;

    socklen_t len;
    size_t rd_sz;

    sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

    if(sock_fd < 0) {
        printf("socket creation error\n");
        perror("socket");
        exit(1);
    }

    bzero(&servaddr,sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port = htons(SERV_PORT);

    bind(sock_fd, (struct sockaddr *) &servaddr, sizeof(servaddr));

    bzero(&evnts,sizeof(evnts));

    evnts.sctp_data_io_event = 1;
    ret = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts, sizeof(evnts));

    if(ret < 0) {
        printf("error setting socket options\n");
        exit(1);
    }

    ret = listen(sock_fd, LISTENQ);

    if(ret < 0) {
        printf("error linstening socket\n");
        perror("listen");
        exit(1);
    }


    for(;;) {
        len = sizeof(struct sockaddr_in);
        rd_sz = sctp_recvmsg(sock_fd, readbuf, sizeof(readbuf),
                             (struct sockaddr *) &cliaddr, &len,
                              &sri, &msg_flags);

        if(rd_sz <= 0) {
            continue;
        }

        printf("From str:%d seq:%d (assoc:0x%x):",
               sri.sinfo_stream,sri.sinfo_ssn,
               (u_int)sri.sinfo_assoc_id);
        printf("%.*s\n",rd_sz,readbuf);

        sctp_sendmsg(sock_fd, readbuf, rd_sz, (struct sockaddr *)&cliaddr,
                     len, sri.sinfo_ppid, sri.sinfo_flags,sri.sinfo_stream,
                     0,0);
    }
}

###############

# client code
###############
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#define MAXLINE     255
#define LISTENQ     1024
#define SERV_PORT   9879
#define BUFFSIZE    8192

int main(int argc, char **argv)

{
    int sock_fd, ret;
    struct sockaddr_in servaddr;
    struct sctp_sndrcvinfo sri;
    struct sctp_event_subscribe evnts;
    char sendline[MAXLINE], recvline[MAXLINE];
    socklen_t len;
    int wr_sz, rd_sz;
    int msg_flags;

    if(argc < 4) {
        printf("Usage: %s [server_ip] [strno] [message]\n",argv[0]);
        exit(1);
    }

    sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

    if(sock_fd < 0) {
        printf("socket creation error\n");
        exit(1);
    }

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port = htons(SERV_PORT);

    ret = inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
    if(ret < 0) {
        perror("inet_pton");
        exit(1);
    }

    bzero(&evnts, sizeof(evnts));
    evnts.sctp_data_io_event = 1;
    ret = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts, sizeof(evnts));

    if(ret < 0) {
        printf("error setting socket options\n");
        exit(1);
    }

    len = sizeof(struct sockaddr_in);
    bzero(&sri, sizeof(sri));
    sri.sinfo_stream = strtol(argv[2],NULL,0);
    snprintf(sendline,MAXLINE,"%s",argv[3]);
    wr_sz = strlen(sendline);

    printf("Say str:%d  msg: %s\n",sri.sinfo_stream, sendline);

    ret = sctp_sendmsg(sock_fd, sendline, wr_sz, (struct sockaddr *) &servaddr,
                       len,0,0,sri.sinfo_stream,0,0);

    if(ret < 0) {
        perror("sctp_sendmsg");
        exit(1);
    }

    len = sizeof(servaddr);

    rd_sz = sctp_recvmsg(sock_fd, recvline, sizeof(recvline),
                         (struct sockaddr *)&servaddr, &len,
                          &sri,&msg_flags);

    if(rd_sz < 0) {
        perror("sctp_recvmsg");
        exit(1);
    }

    printf("echo str:%d seq:%d (assoc:0x%x):",
           sri.sinfo_stream,sri.sinfo_ssn,
           (u_int)sri.sinfo_assoc_id);
    printf("%.*s\n",rd_sz,recvline);

}

#1 lore raw
Quoted 10 lines · Horacio Sanson

I have a small echo server/client program for testing. It works in linux kernel 2.6.22-14 (Ubuntu) but using the latest lksctp-dev tree (from git) I get "invalid parameter" errors when calling sctp_sendmsg().

Any directions are appreciated:

Horacio

There are several reasons that sctp_sendmsg may return EINVAL from the kernel, but none of those reasons has changed in any real way in quite some time. My first guess would be that there is some incompatibility between the lastest kernel and the version of lksctp-tools that implements sctp_sendmsg in userspace for you on your system. I'd recommend grabbing the latest lksctp-tools package from upstream and trying to link your code against that before you go chasing any real bugs.

Neil

Quoted 186 lines

###############

# server code
###############
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#define MAXLINE     255
#define LISTENQ     1024
#define SERV_PORT   9879
#define BUFFSIZE    8192

int main(int arvc, char **argv)

{
    int sock_fd, msg_flags, ret;
    char readbuf[BUFFSIZE];

    struct sockaddr_in servaddr, cliaddr;
    struct sctp_sndrcvinfo sri;
    struct sctp_event_subscribe evnts;

    socklen_t len;
    size_t rd_sz;

    sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

    if(sock_fd < 0) {
        printf("socket creation error\n");
        perror("socket");
        exit(1);
    }

    bzero(&servaddr,sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port = htons(SERV_PORT);

    bind(sock_fd, (struct sockaddr *) &servaddr, sizeof(servaddr));

    bzero(&evnts,sizeof(evnts));

    evnts.sctp_data_io_event = 1;
    ret = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts, sizeof(evnts));

    if(ret < 0) {
        printf("error setting socket options\n");
        exit(1);
    }

    ret = listen(sock_fd, LISTENQ);

    if(ret < 0) {
        printf("error linstening socket\n");
        perror("listen");
        exit(1);
    }


    for(;;) {
        len = sizeof(struct sockaddr_in);
        rd_sz = sctp_recvmsg(sock_fd, readbuf, sizeof(readbuf),
                             (struct sockaddr *) &cliaddr, &len,
                              &sri, &msg_flags);

        if(rd_sz <= 0) {
            continue;
        }

        printf("From str:%d seq:%d (assoc:0x%x):",
               sri.sinfo_stream,sri.sinfo_ssn,
               (u_int)sri.sinfo_assoc_id);
        printf("%.*s\n",rd_sz,readbuf);

        sctp_sendmsg(sock_fd, readbuf, rd_sz, (struct sockaddr *)&cliaddr,
                     len, sri.sinfo_ppid, sri.sinfo_flags,sri.sinfo_stream,
                     0,0);
    }
}

###############

# client code
###############
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#define MAXLINE     255
#define LISTENQ     1024
#define SERV_PORT   9879
#define BUFFSIZE    8192

int main(int argc, char **argv)

{
    int sock_fd, ret;
    struct sockaddr_in servaddr;
    struct sctp_sndrcvinfo sri;
    struct sctp_event_subscribe evnts;
    char sendline[MAXLINE], recvline[MAXLINE];
    socklen_t len;
    int wr_sz, rd_sz;
    int msg_flags;

    if(argc < 4) {
        printf("Usage: %s [server_ip] [strno] [message]\n",argv[0]);
        exit(1);
    }

    sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

    if(sock_fd < 0) {
        printf("socket creation error\n");
        exit(1);
    }

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port = htons(SERV_PORT);

    ret = inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
    if(ret < 0) {
        perror("inet_pton");
        exit(1);
    }

    bzero(&evnts, sizeof(evnts));
    evnts.sctp_data_io_event = 1;
    ret = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts, sizeof(evnts));

    if(ret < 0) {
        printf("error setting socket options\n");
        exit(1);
    }

    len = sizeof(struct sockaddr_in);
    bzero(&sri, sizeof(sri));
    sri.sinfo_stream = strtol(argv[2],NULL,0);
    snprintf(sendline,MAXLINE,"%s",argv[3]);
    wr_sz = strlen(sendline);

    printf("Say str:%d  msg: %s\n",sri.sinfo_stream, sendline);

    ret = sctp_sendmsg(sock_fd, sendline, wr_sz, (struct sockaddr *) &servaddr,
                       len,0,0,sri.sinfo_stream,0,0);

    if(ret < 0) {
        perror("sctp_sendmsg");
        exit(1);
    }

    len = sizeof(servaddr);

    rd_sz = sctp_recvmsg(sock_fd, recvline, sizeof(recvline),
                         (struct sockaddr *)&servaddr, &len,
                          &sri,&msg_flags);

    if(rd_sz < 0) {
        perror("sctp_recvmsg");
        exit(1);
    }

    printf("echo str:%d seq:%d (assoc:0x%x):",
           sri.sinfo_stream,sri.sinfo_ssn,
           (u_int)sri.sinfo_assoc_id);
    printf("%.*s\n",rd_sz,recvline);

}
--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 4 lines
/****************************************************
 * Neil Horman <[email protected]>
 * Software Engineer, Red Hat
 ****************************************************/
#2 lore raw
In reply to Horacio Sanson

Is there some way to ask a running linux kernel which version of lksctp-tools it needs ?

Quoted 10 lines · Neil Horman
Quoted 8 lines · Horacio Sanson

I have a small echo server/client program for testing. It works in linux kernel 2.6.22-14 (Ubuntu) but using the latest lksctp-dev tree (from git) I get "invalid parameter" errors when calling sctp_sendmsg().

Any directions are appreciated:

Horacio

Signature · 1 line
David Pascoe, [email protected]
#3 lore raw
In reply to Horacio Sanson
Quoted 2 lines · David Pascoe

Is there some way to ask a running linux kernel which version of lksctp-tools it needs ?

No, there currently isn't any version information in lksctp. I've checked the tools history and there is nothing there that changed.

The older libraries should still work on the newer kernels

Let me take a look and see why there is an error.

-vlad

Quoted 13 lines · Neil Horman
Quoted 10 lines · Horacio Sanson
Quoted 8 lines

I have a small echo server/client program for testing. It works in linux kernel 2.6.22-14 (Ubuntu) but using the latest lksctp-dev tree (from git) I get "invalid parameter" errors when calling sctp_sendmsg().

Any directions are appreciated:

Horacio

#4 lore raw
In reply to Horacio Sanson

Hi Horacio

Quoted 6 lines · Horacio Sanson

I have a small echo server/client program for testing. It works in linux kernel 2.6.22-14 (Ubuntu) but using the latest lksctp-dev tree (from git) I get "invalid parameter" errors when calling sctp_sendmsg().

Any directions are appreciated:

I just tried running this on the .git kernel with 1.0.6, 1.0.7, 1.0.8 libraries. It worked in all cases.

The test was run over loopback with

 # client 127.0.0.1 9 "Stream 9"

If you are trying to use more then 10 streams (0 - 9), then you need to tell lksctp that using SCTP_INITMSG socket option or ancillary data. This is what's most likely generating an error for you (at least that did it for me).

-vlad

Quoted 191 lines

Horacio

###############

# server code
###############
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#define MAXLINE     255
#define LISTENQ     1024
#define SERV_PORT   9879
#define BUFFSIZE    8192

int main(int arvc, char **argv)

{
    int sock_fd, msg_flags, ret;
    char readbuf[BUFFSIZE];

    struct sockaddr_in servaddr, cliaddr;
    struct sctp_sndrcvinfo sri;
    struct sctp_event_subscribe evnts;

    socklen_t len;
    size_t rd_sz;

    sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

    if(sock_fd < 0) {
        printf("socket creation error\n");
        perror("socket");
        exit(1);
    }

    bzero(&servaddr,sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port = htons(SERV_PORT);

    bind(sock_fd, (struct sockaddr *) &servaddr, sizeof(servaddr));

    bzero(&evnts,sizeof(evnts));

    evnts.sctp_data_io_event = 1;
    ret = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts, sizeof(evnts));

    if(ret < 0) {
        printf("error setting socket options\n");
        exit(1);
    }

    ret = listen(sock_fd, LISTENQ);

    if(ret < 0) {
        printf("error linstening socket\n");
        perror("listen");
        exit(1);
    }


    for(;;) {
        len = sizeof(struct sockaddr_in);
        rd_sz = sctp_recvmsg(sock_fd, readbuf, sizeof(readbuf),
                             (struct sockaddr *) &cliaddr, &len,
                              &sri, &msg_flags);

        if(rd_sz <= 0) {
            continue;
        }

        printf("From str:%d seq:%d (assoc:0x%x):",
               sri.sinfo_stream,sri.sinfo_ssn,
               (u_int)sri.sinfo_assoc_id);
        printf("%.*s\n",rd_sz,readbuf);

        sctp_sendmsg(sock_fd, readbuf, rd_sz, (struct sockaddr *)&cliaddr,
                     len, sri.sinfo_ppid, sri.sinfo_flags,sri.sinfo_stream,
                     0,0);
    }
}

###############

# client code
###############
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#define MAXLINE     255
#define LISTENQ     1024
#define SERV_PORT   9879
#define BUFFSIZE    8192

int main(int argc, char **argv)

{
    int sock_fd, ret;
    struct sockaddr_in servaddr;
    struct sctp_sndrcvinfo sri;
    struct sctp_event_subscribe evnts;
    char sendline[MAXLINE], recvline[MAXLINE];
    socklen_t len;
    int wr_sz, rd_sz;
    int msg_flags;

    if(argc < 4) {
        printf("Usage: %s [server_ip] [strno] [message]\n",argv[0]);
        exit(1);
    }

    sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

    if(sock_fd < 0) {
        printf("socket creation error\n");
        exit(1);
    }

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port = htons(SERV_PORT);

    ret = inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
    if(ret < 0) {
        perror("inet_pton");
        exit(1);
    }

    bzero(&evnts, sizeof(evnts));
    evnts.sctp_data_io_event = 1;
    ret = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts, sizeof(evnts));

    if(ret < 0) {
        printf("error setting socket options\n");
        exit(1);
    }

    len = sizeof(struct sockaddr_in);
    bzero(&sri, sizeof(sri));
    sri.sinfo_stream = strtol(argv[2],NULL,0);
    snprintf(sendline,MAXLINE,"%s",argv[3]);
    wr_sz = strlen(sendline);

    printf("Say str:%d  msg: %s\n",sri.sinfo_stream, sendline);

    ret = sctp_sendmsg(sock_fd, sendline, wr_sz, (struct sockaddr *) &servaddr,
                       len,0,0,sri.sinfo_stream,0,0);

    if(ret < 0) {
        perror("sctp_sendmsg");
        exit(1);
    }

    len = sizeof(servaddr);

    rd_sz = sctp_recvmsg(sock_fd, recvline, sizeof(recvline),
                         (struct sockaddr *)&servaddr, &len,
                          &sri,&msg_flags);

    if(rd_sz < 0) {
        perror("sctp_recvmsg");
        exit(1);
    }

    printf("echo str:%d seq:%d (assoc:0x%x):",
           sri.sinfo_stream,sri.sinfo_ssn,
           (u_int)sri.sinfo_assoc_id);
    printf("%.*s\n",rd_sz,recvline);

}
--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
In reply to Horacio Sanson

Thanks for the replies,

Quoted 10 lines · Vlad Yasevich

Hi Horacio

Quoted 5 lines · Horacio Sanson

I have a small echo server/client program for testing. It works in linux kernel 2.6.22-14 (Ubuntu) but using the latest lksctp-dev tree (from git) I get "invalid parameter" errors when calling sctp_sendmsg().

Quoted 6 lines
Quoted 2 lines

Any directions are appreciated:

I just tried running this on the .git kernel with 1.0.6, 1.0.7, 1.0.8 libraries. It worked in all cases.

Indeed running the code using sctp-tools 1.0.8 in kernel 2.6.22 works flawlessly. But with the latest kernel from git (2.6.25-rc8) it does not work. It gives me "invalid parameter" errors when calling sctp_sendmsg().

I am no good at kernel development, but any tips on how to debug this are appreciated.

regards,
Horacio

Quoted 212 lines

The test was run over loopback with

 # client 127.0.0.1 9 "Stream 9"

If you are trying to use more then 10 streams (0 - 9), then you need to tell lksctp that using SCTP_INITMSG socket option or ancillary data. This is what's most likely generating an error for you (at least that did it for me).

-vlad

Quoted 48 lines

Horacio

###############

# server code
###############
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#define MAXLINE     255
#define LISTENQ     1024
#define SERV_PORT   9879
#define BUFFSIZE    8192

int main(int arvc, char **argv)

{
   int sock_fd, msg_flags, ret;
   char readbuf[BUFFSIZE];

   struct sockaddr_in servaddr, cliaddr;
   struct sctp_sndrcvinfo sri;
   struct sctp_event_subscribe evnts;

   socklen_t len;
   size_t rd_sz;

   sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

   if(sock_fd < 0) {
       printf("socket creation error\n");
       perror("socket");
       exit(1);
   }

   bzero(&servaddr,sizeof(servaddr));
   servaddr.sin_family = AF_INET;
   servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
Quoted 8 lines
   servaddr.sin_port = htons(SERV_PORT);

   bind(sock_fd, (struct sockaddr *) &servaddr, sizeof(servaddr));

   bzero(&evnts,sizeof(evnts));

   evnts.sctp_data_io_event = 1;
   ret = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts,

sizeof(evnts));

Quoted 86 lines
   if(ret < 0) {
       printf("error setting socket options\n");
       exit(1);
   }

   ret = listen(sock_fd, LISTENQ);

   if(ret < 0) {
       printf("error linstening socket\n");
       perror("listen");
       exit(1);
   }
   for(;;) {
       len = sizeof(struct sockaddr_in);
       rd_sz = sctp_recvmsg(sock_fd, readbuf, sizeof(readbuf),
                            (struct sockaddr *) &cliaddr, &len,
                             &sri, &msg_flags);

       if(rd_sz <= 0) {
           continue;
       }

       printf("From str:%d seq:%d (assoc:0x%x):",
              sri.sinfo_stream,sri.sinfo_ssn,
              (u_int)sri.sinfo_assoc_id);
       printf("%.*s\n",rd_sz,readbuf);

       sctp_sendmsg(sock_fd, readbuf, rd_sz, (struct sockaddr *)&cliaddr,
                    len, sri.sinfo_ppid, sri.sinfo_flags,sri.sinfo_stream,
                    0,0);
   }
}

###############

# client code
###############
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#define MAXLINE     255
#define LISTENQ     1024
#define SERV_PORT   9879
#define BUFFSIZE    8192

int main(int argc, char **argv)

{
   int sock_fd, ret;
   struct sockaddr_in servaddr;
   struct sctp_sndrcvinfo sri;
   struct sctp_event_subscribe evnts;
   char sendline[MAXLINE], recvline[MAXLINE];
   socklen_t len;
   int wr_sz, rd_sz;
   int msg_flags;

   if(argc < 4) {
       printf("Usage: %s [server_ip] [strno] [message]\n",argv[0]);
       exit(1);
   }

   sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

   if(sock_fd < 0) {
       printf("socket creation error\n");
       exit(1);
   }

   bzero(&servaddr, sizeof(servaddr));
   servaddr.sin_family = AF_INET;
   servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
   servaddr.sin_port = htons(SERV_PORT);

   ret = inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
Quoted 8 lines
   if(ret < 0) {
       perror("inet_pton");
       exit(1);
   }

   bzero(&evnts, sizeof(evnts));
   evnts.sctp_data_io_event = 1;
   ret = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts,

sizeof(evnts));

Quoted 14 lines
   if(ret < 0) {
       printf("error setting socket options\n");
       exit(1);
   }

   len = sizeof(struct sockaddr_in);
   bzero(&sri, sizeof(sri));
   sri.sinfo_stream = strtol(argv[2],NULL,0);
   snprintf(sendline,MAXLINE,"%s",argv[3]);
   wr_sz = strlen(sendline);

   printf("Say str:%d  msg: %s\n",sri.sinfo_stream, sendline);
Quoted 1 line

ret = sctp_sendmsg(sock_fd, sendline, wr_sz, (struct sockaddr *)

&servaddr,

Quoted 31 lines
                      len,0,0,sri.sinfo_stream,0,0);
   if(ret < 0) {
       perror("sctp_sendmsg");
       exit(1);
   }

   len = sizeof(servaddr);
   rd_sz = sctp_recvmsg(sock_fd, recvline, sizeof(recvline),
                        (struct sockaddr *)&servaddr, &len,
                         &sri,&msg_flags);

   if(rd_sz < 0) {
       perror("sctp_recvmsg");
       exit(1);
   }

   printf("echo str:%d seq:%d (assoc:0x%x):",
          sri.sinfo_stream,sri.sinfo_ssn,
          (u_int)sri.sinfo_assoc_id);
   printf("%.*s\n",rd_sz,recvline);

}

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
In reply to Horacio Sanson
Quoted 17 lines · Horacio Sanson

Thanks for the replies,

Quoted 13 lines · Vlad Yasevich

Hi Horacio

Quoted 7 lines · Horacio Sanson

I have a small echo server/client program for testing. It works in linux kernel 2.6.22-14 (Ubuntu) but using the latest lksctp-dev tree (from git) I get "invalid parameter" errors when calling sctp_sendmsg().

Any directions are appreciated:

Quoted 9 lines
Quoted 3 lines

I just tried running this on the .git kernel with 1.0.6, 1.0.7, 1.0.8 libraries. It worked in all cases.

Indeed running the code using sctp-tools 1.0.8 in kernel 2.6.22 works flawlessly. But with the latest kernel from git (2.6.25-rc8) it does not work. It gives me "invalid parameter" errors when calling sctp_sendmsg().

Are you using the sctp-tools packaged by ubuntu, or building them yourself? I wouldn't think this to be the case, but its possible that the maintainer at ubuntu included a patch unique to their distro's sctp-tools thats breaking your setup. I'd check their packaging metadata for something like that.

Neil

Quoted 222 lines

I am no good at kernel development, but any tips on how to debug this are appreciated.

regards,
Horacio

Quoted 175 lines

The test was run over loopback with

 # client 127.0.0.1 9 "Stream 9"

If you are trying to use more then 10 streams (0 - 9), then you need to tell lksctp that using SCTP_INITMSG socket option or ancillary data. This is what's most likely generating an error for you (at least that did it for me).

-vlad

Quoted 48 lines

Horacio

###############

# server code
###############
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#define MAXLINE     255
#define LISTENQ     1024
#define SERV_PORT   9879
#define BUFFSIZE    8192

int main(int arvc, char **argv)

{
   int sock_fd, msg_flags, ret;
   char readbuf[BUFFSIZE];

   struct sockaddr_in servaddr, cliaddr;
   struct sctp_sndrcvinfo sri;
   struct sctp_event_subscribe evnts;

   socklen_t len;
   size_t rd_sz;

   sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

   if(sock_fd < 0) {
       printf("socket creation error\n");
       perror("socket");
       exit(1);
   }

   bzero(&servaddr,sizeof(servaddr));
   servaddr.sin_family = AF_INET;
   servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
Quoted 8 lines
   servaddr.sin_port = htons(SERV_PORT);

   bind(sock_fd, (struct sockaddr *) &servaddr, sizeof(servaddr));

   bzero(&evnts,sizeof(evnts));

   evnts.sctp_data_io_event = 1;
   ret = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts,

sizeof(evnts));

Quoted 86 lines
   if(ret < 0) {
       printf("error setting socket options\n");
       exit(1);
   }

   ret = listen(sock_fd, LISTENQ);

   if(ret < 0) {
       printf("error linstening socket\n");
       perror("listen");
       exit(1);
   }
   for(;;) {
       len = sizeof(struct sockaddr_in);
       rd_sz = sctp_recvmsg(sock_fd, readbuf, sizeof(readbuf),
                            (struct sockaddr *) &cliaddr, &len,
                             &sri, &msg_flags);

       if(rd_sz <= 0) {
           continue;
       }

       printf("From str:%d seq:%d (assoc:0x%x):",
              sri.sinfo_stream,sri.sinfo_ssn,
              (u_int)sri.sinfo_assoc_id);
       printf("%.*s\n",rd_sz,readbuf);

       sctp_sendmsg(sock_fd, readbuf, rd_sz, (struct sockaddr *)&cliaddr,
                    len, sri.sinfo_ppid, sri.sinfo_flags,sri.sinfo_stream,
                    0,0);
   }
}

###############

# client code
###############
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#define MAXLINE     255
#define LISTENQ     1024
#define SERV_PORT   9879
#define BUFFSIZE    8192

int main(int argc, char **argv)

{
   int sock_fd, ret;
   struct sockaddr_in servaddr;
   struct sctp_sndrcvinfo sri;
   struct sctp_event_subscribe evnts;
   char sendline[MAXLINE], recvline[MAXLINE];
   socklen_t len;
   int wr_sz, rd_sz;
   int msg_flags;

   if(argc < 4) {
       printf("Usage: %s [server_ip] [strno] [message]\n",argv[0]);
       exit(1);
   }

   sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

   if(sock_fd < 0) {
       printf("socket creation error\n");
       exit(1);
   }

   bzero(&servaddr, sizeof(servaddr));
   servaddr.sin_family = AF_INET;
   servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
   servaddr.sin_port = htons(SERV_PORT);

   ret = inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
Quoted 8 lines
   if(ret < 0) {
       perror("inet_pton");
       exit(1);
   }

   bzero(&evnts, sizeof(evnts));
   evnts.sctp_data_io_event = 1;
   ret = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts,

sizeof(evnts));

Quoted 12 lines
   if(ret < 0) {
       printf("error setting socket options\n");
       exit(1);
   }

   len = sizeof(struct sockaddr_in);
   bzero(&sri, sizeof(sri));
   sri.sinfo_stream = strtol(argv[2],NULL,0);
   snprintf(sendline,MAXLINE,"%s",argv[3]);
   wr_sz = strlen(sendline);
Quoted 37 lines
Quoted 3 lines
   printf("Say str:%d  msg: %s\n",sri.sinfo_stream, sendline);

ret = sctp_sendmsg(sock_fd, sendline, wr_sz, (struct sockaddr *)

&servaddr,

Quoted 31 lines
                      len,0,0,sri.sinfo_stream,0,0);
   if(ret < 0) {
       perror("sctp_sendmsg");
       exit(1);
   }

   len = sizeof(servaddr);
   rd_sz = sctp_recvmsg(sock_fd, recvline, sizeof(recvline),
                        (struct sockaddr *)&servaddr, &len,
                         &sri,&msg_flags);

   if(rd_sz < 0) {
       perror("sctp_recvmsg");
       exit(1);
   }

   printf("echo str:%d seq:%d (assoc:0x%x):",
          sri.sinfo_stream,sri.sinfo_ssn,
          (u_int)sri.sinfo_assoc_id);
   printf("%.*s\n",rd_sz,recvline);

}

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 4 lines
/****************************************************
 * Neil Horman <[email protected]>
 * Software Engineer, Red Hat
 ****************************************************/
#7 lore raw
In reply to Horacio Sanson
Quoted 27 lines · Neil Horman
Quoted 17 lines · Horacio Sanson

Thanks for the replies,

Quoted 13 lines · Vlad Yasevich

Hi Horacio

Quoted 7 lines · Horacio Sanson

I have a small echo server/client program for testing. It works in linux kernel 2.6.22-14 (Ubuntu) but using the latest lksctp-dev tree (from git) I get "invalid parameter" errors when calling sctp_sendmsg().

Any directions are appreciated:

Quoted 9 lines
Quoted 3 lines

I just tried running this on the .git kernel with 1.0.6, 1.0.7, 1.0.8 libraries. It worked in all cases.

Indeed running the code using sctp-tools 1.0.8 in kernel 2.6.22 works flawlessly. But with the latest kernel from git (2.6.25-rc8) it does not work. It gives me "invalid parameter" errors when calling sctp_sendmsg().

Quoted 8 lines

Are you using the sctp-tools packaged by ubuntu, or building them yourself? I wouldn't think this to be the case, but its possible that the maintainer at ubuntu included a patch unique to their distro's sctp-tools thats breaking your setup. I'd check their packaging metadata for something like that.

Neil

I am using the lksctp-dev kernel and the lksctp-tools both up to date from git repository. I also checked that the only libsctp library I have is the one from git and made sure to load the sctp kernel modules.

I must mention that this program worked fine before with kernel 2.6.25-rc3 but after a recent update of lksctp-dev to 2.6.25-rc8 a few days ago it started failing.....

For now I will keep working with the 2.6.22 kernel.

thanks
Horacio

Quoted 232 lines
Quoted 220 lines

I am no good at kernel development, but any tips on how to debug this are appreciated.

regards,
Horacio

Quoted 175 lines

The test was run over loopback with

 # client 127.0.0.1 9 "Stream 9"

If you are trying to use more then 10 streams (0 - 9), then you need to tell lksctp that using SCTP_INITMSG socket option or ancillary data. This is what's most likely generating an error for you (at least that did it for me).

-vlad

Quoted 48 lines

Horacio

###############

# server code
###############
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#define MAXLINE     255
#define LISTENQ     1024
#define SERV_PORT   9879
#define BUFFSIZE    8192

int main(int arvc, char **argv)

{
   int sock_fd, msg_flags, ret;
   char readbuf[BUFFSIZE];

   struct sockaddr_in servaddr, cliaddr;
   struct sctp_sndrcvinfo sri;
   struct sctp_event_subscribe evnts;

   socklen_t len;
   size_t rd_sz;

   sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

   if(sock_fd < 0) {
       printf("socket creation error\n");
       perror("socket");
       exit(1);
   }

   bzero(&servaddr,sizeof(servaddr));
   servaddr.sin_family = AF_INET;
   servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
Quoted 8 lines
   servaddr.sin_port = htons(SERV_PORT);

   bind(sock_fd, (struct sockaddr *) &servaddr, sizeof(servaddr));

   bzero(&evnts,sizeof(evnts));

   evnts.sctp_data_io_event = 1;
   ret = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts,

sizeof(evnts));

Quoted 86 lines
   if(ret < 0) {
       printf("error setting socket options\n");
       exit(1);
   }

   ret = listen(sock_fd, LISTENQ);

   if(ret < 0) {
       printf("error linstening socket\n");
       perror("listen");
       exit(1);
   }
   for(;;) {
       len = sizeof(struct sockaddr_in);
       rd_sz = sctp_recvmsg(sock_fd, readbuf, sizeof(readbuf),
                            (struct sockaddr *) &cliaddr, &len,
                             &sri, &msg_flags);

       if(rd_sz <= 0) {
           continue;
       }

       printf("From str:%d seq:%d (assoc:0x%x):",
              sri.sinfo_stream,sri.sinfo_ssn,
              (u_int)sri.sinfo_assoc_id);
       printf("%.*s\n",rd_sz,readbuf);

       sctp_sendmsg(sock_fd, readbuf, rd_sz, (struct sockaddr *)&cliaddr,
                    len, sri.sinfo_ppid, sri.sinfo_flags,sri.sinfo_stream,
                    0,0);
   }
}

###############

# client code
###############
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#define MAXLINE     255
#define LISTENQ     1024
#define SERV_PORT   9879
#define BUFFSIZE    8192

int main(int argc, char **argv)

{
   int sock_fd, ret;
   struct sockaddr_in servaddr;
   struct sctp_sndrcvinfo sri;
   struct sctp_event_subscribe evnts;
   char sendline[MAXLINE], recvline[MAXLINE];
   socklen_t len;
   int wr_sz, rd_sz;
   int msg_flags;

   if(argc < 4) {
       printf("Usage: %s [server_ip] [strno] [message]\n",argv[0]);
       exit(1);
   }

   sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

   if(sock_fd < 0) {
       printf("socket creation error\n");
       exit(1);
   }

   bzero(&servaddr, sizeof(servaddr));
   servaddr.sin_family = AF_INET;
   servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
   servaddr.sin_port = htons(SERV_PORT);

   ret = inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
Quoted 8 lines
   if(ret < 0) {
       perror("inet_pton");
       exit(1);
   }

   bzero(&evnts, sizeof(evnts));
   evnts.sctp_data_io_event = 1;
   ret = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts,

sizeof(evnts));

Quoted 12 lines
   if(ret < 0) {
       printf("error setting socket options\n");
       exit(1);
   }

   len = sizeof(struct sockaddr_in);
   bzero(&sri, sizeof(sri));
   sri.sinfo_stream = strtol(argv[2],NULL,0);
   snprintf(sendline,MAXLINE,"%s",argv[3]);
   wr_sz = strlen(sendline);
Quoted 37 lines
Quoted 3 lines
   printf("Say str:%d  msg: %s\n",sri.sinfo_stream, sendline);

ret = sctp_sendmsg(sock_fd, sendline, wr_sz, (struct sockaddr *)

&servaddr,

Quoted 31 lines
                      len,0,0,sri.sinfo_stream,0,0);
   if(ret < 0) {
       perror("sctp_sendmsg");
       exit(1);
   }

   len = sizeof(servaddr);
   rd_sz = sctp_recvmsg(sock_fd, recvline, sizeof(recvline),
                        (struct sockaddr *)&servaddr, &len,
                         &sri,&msg_flags);

   if(rd_sz < 0) {
       perror("sctp_recvmsg");
       exit(1);
   }

   printf("echo str:%d seq:%d (assoc:0x%x):",
          sri.sinfo_stream,sri.sinfo_ssn,
          (u_int)sri.sinfo_assoc_id);
   printf("%.*s\n",rd_sz,recvline);

}

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

-- /****************************************************

* Neil Horman <[email protected]>
* Software Engineer, Red Hat ****************************************************/

#8 lore raw
In reply to Horacio Sanson
Quoted 11 lines · Horacio Sanson

I am using the lksctp-dev kernel and the lksctp-tools both up to date from git repository. I also checked that the only libsctp library I have is the one from git and made sure to load the sctp kernel modules.

I must mention that this program worked fine before with kernel 2.6.25-rc3 but after a recent update of lksctp-dev to 2.6.25-rc8 a few days ago it started failing.....

For now I will keep working with the 2.6.22 kernel.

would you be able to do a bisect?

# git-bisect start 
# git-bisect bad
# git-bisect good v2.6.24-rc3

I'd do it if I could reproduce the problem.

Thanks
-vlad

#9 lore raw
In reply to Horacio Sanson
Quoted 12 lines · Vlad Yasevich
Quoted 9 lines · Horacio Sanson

I am using the lksctp-dev kernel and the lksctp-tools both up to date from git repository. I also checked that the only libsctp library I have is the one from git and made sure to load the sctp kernel modules.

I must mention that this program worked fine before with kernel 2.6.25-rc3 but after a recent update of lksctp-dev to 2.6.25-rc8 a few days ago it started failing.....

Quoted 9 lines
Quoted 3 lines

For now I will keep working with the 2.6.22 kernel.

would you be able to do a bisect?

 # git-bisect start # git-bisect bad
 # git-bisect good v2.6.24-rc3

Sorry I completely removed the git repository tree and did a new clone. Now everything is working fine with the latest kernel 2.6.25-rc8.

thanks for the help
Horacio

Quoted 6 lines

I'd do it if I could reproduce the problem.

Thanks
-vlad

#10 lore raw
In reply to Horacio Sanson
Quoted 19 lines · Horacio Sanson
Quoted 17 lines · Vlad Yasevich
Quoted 5 lines · Horacio Sanson

I am using the lksctp-dev kernel and the lksctp-tools both up to date from git repository. I also checked that the only libsctp library I have is the one from git and made sure to load the sctp kernel modules.

Quoted 7 lines

I must mention that this program worked fine before with kernel 2.6.25-rc3 but after a recent update of lksctp-dev to 2.6.25-rc8 a few days ago it started failing.....

For now I will keep working with the 2.6.22 kernel.

would you be able to do a bisect?

Quoted 7 lines
Quoted 3 lines
 # git-bisect start # git-bisect bad
 # git-bisect good v2.6.24-rc3

Sorry I completely removed the git repository tree and did a new clone. Now everything is working fine with the latest kernel 2.6.25-rc8.

Glad it worked. I thought it was something with my setup.

Thanks
-vlad