[PATCH v2] net/tcp: Account for connection teardown handshake

2019-09-20 Thread Sebastian Smolorz via Xenomai
When closing a TCP connection a handshake procedure is executed between the
peers. The close routine of the rttcp driver did not participate in
detecting the end of this handshake but rather waited one second inside
a close call unconditionally. Especially when peers are directly connected
this is a waste of time which can hurt a lot in some situations.

This patch replaces the msleep(1000) call with waiting for a completion.
The maximum waiting time now can be configured via a module parameter.
The completion is done when the termination handshake has finished.

Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 38 ++---
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index 54bafa80f..b8263e5d2 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 

@@ -41,6 +42,11 @@
 #include 
 #include "timerwheel.h"

+static unsigned int close_timeout = 1000;
+module_param(close_timeout, uint, 0664);
+MODULE_PARM_DESC(close_timeout,
+"max time (ms) to wait during close for FIN-ACK handshake to 
complete, default 1000");
+
 #ifdef CONFIG_XENO_DRIVERS_NET_RTIPV4_TCP_ERROR_INJECTION

 static unsigned int error_rate;
@@ -147,6 +153,9 @@ struct tcp_socket {
struct rtskb_queue retransmit_queue;
struct timerwheel_timer timer;

+   struct completion fin_handshake;
+   rtdm_nrtsig_t close_sig;
+
 #ifdef CONFIG_XENO_DRIVERS_NET_RTIPV4_TCP_ERROR_INJECTION
unsigned int packet_counter;
unsigned int error_rate;
@@ -1042,6 +1051,7 @@ static void rt_tcp_rcv(struct rtskb *skb)
rt_tcp_send(ts, TCP_FLAG_ACK);
/* data receiving is not possible anymore */
rtdm_sem_destroy(>sock.pending_sem);
+   rtdm_nrtsig_pend(>close_sig);
goto feed;
} else if (ts->tcp_state == TCP_FIN_WAIT1) {
/* Send ACK */
@@ -1105,6 +1115,7 @@ static void rt_tcp_rcv(struct rtskb *skb)
ts->tcp_state = TCP_CLOSE;
rtdm_lock_put_irqrestore(>socket_lock, context);
/* socket destruction will be done on close() */
+   rtdm_nrtsig_pend(>close_sig);
goto drop;
} else if (ts->tcp_state == TCP_FIN_WAIT1) {
ts->tcp_state = TCP_FIN_WAIT2;
@@ -1119,6 +1130,7 @@ static void rt_tcp_rcv(struct rtskb *skb)
ts->tcp_state = TCP_TIME_WAIT;
rtdm_lock_put_irqrestore(>socket_lock, context);
/* socket destruction will be done on close() */
+   rtdm_nrtsig_pend(>close_sig);
goto feed;
}
}
@@ -1190,6 +1202,11 @@ static int rt_tcp_window_send(struct tcp_socket *ts, u32 
data_len, u8 *data_ptr)
return ret;
 }

+static void rt_tcp_close_signal_handler(rtdm_nrtsig_t *nrtsig, void *arg)
+{
+   complete_all((struct completion *)arg);
+}
+
 static int rt_tcp_socket_create(struct tcp_socket *ts)
 {
rtdm_lockctx_t context;
@@ -1226,6 +1243,10 @@ static int rt_tcp_socket_create(struct tcp_socket *ts)
timerwheel_init_timer(>timer, rt_tcp_retransmit_handler, ts);
rtskb_queue_init(>retransmit_queue);

+   init_completion(>fin_handshake);
+   rtdm_nrtsig_init(>close_sig, rt_tcp_close_signal_handler,
+>fin_handshake);
+
 #ifdef CONFIG_XENO_DRIVERS_NET_RTIPV4_TCP_ERROR_INJECTION
ts->packet_counter = counter_start;
ts->error_rate = error_rate;
@@ -1237,6 +1258,7 @@ static int rt_tcp_socket_create(struct tcp_socket *ts)
/* enforce maximum number of TCP sockets */
if (free_ports == 0) {
rtdm_lock_put_irqrestore(_socket_base_lock, context);
+   rtdm_nrtsig_destroy(>close_sig);
return -EAGAIN;
}
free_ports--;
@@ -1338,6 +1360,8 @@ static void rt_tcp_socket_destruct(struct tcp_socket *ts)

rtdm_event_destroy(>conn_evt);

+   rtdm_nrtsig_destroy(>close_sig);
+
/* cleanup already collected fragments */
rt_ip_frag_invalidate_socket(sock);

@@ -1379,8 +1403,11 @@ static void rt_tcp_close(struct rtdm_fd *fd)
   sizeof(send_cmd), NULL, NULL);
/* result is ignored */

-   /* Give the peer some time to reply to our FIN. */
-   msleep(1000);
+   /* Give the peer some time to reply to our FIN.
+  Since it is not relevant what exactly causes the wait
+  function to return 

Re: [PATCH] net/tcp: Account for connection teardown handshake

2019-09-18 Thread Sebastian Smolorz via Xenomai
On 17.09.19 14:46, Jan Kiszka wrote:
> On 17.09.19 14:01, Sebastian Smolorz wrote:
> > When closing a TCP connection a handshake procedure is executed between the
> > peers. The close routine of the rttcp driver did not participate in
> > detecting the end of this handshake but rather waited one second inside
> > a close call unconditionally. Especially when peers are directly connected
> > this is a waste of time which can hurt a lot in some situations.
> >
> > This patch replaces the msleep(1000) call with a timed wait on a
> > semaphore which gets sigalled when the termination handshake is complete.
> >
> > Signed-off-by: Sebastian Smolorz 
> > ---
> >   kernel/drivers/net/stack/ipv4/tcp/tcp.c | 29 +++--
> >   1 file changed, 27 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
> > b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
> > index 54bafa80f..81089afd1 100644
> > --- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
> > +++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
> > @@ -147,6 +147,9 @@ struct tcp_socket {
> > struct rtskb_queue retransmit_queue;
> > struct timerwheel_timer timer;
> >
> > +   struct semaphore close_sem;
>
> Sounds rather lake a job for struct completion.

Yes, will change it.

>
> > +   rtdm_nrtsig_t close_sig;
> > +
> >   #ifdef CONFIG_XENO_DRIVERS_NET_RTIPV4_TCP_ERROR_INJECTION
> > unsigned int packet_counter;
> > unsigned int error_rate;
> > @@ -1042,6 +1045,7 @@ static void rt_tcp_rcv(struct rtskb *skb)
> > rt_tcp_send(ts, TCP_FLAG_ACK);
> > /* data receiving is not possible anymore */
> > rtdm_sem_destroy(>sock.pending_sem);
> > +   rtdm_nrtsig_pend(>close_sig);
> > goto feed;
> > } else if (ts->tcp_state == TCP_FIN_WAIT1) {
> > /* Send ACK */
> > @@ -1105,6 +1109,7 @@ static void rt_tcp_rcv(struct rtskb *skb)
> > ts->tcp_state = TCP_CLOSE;
> > rtdm_lock_put_irqrestore(>socket_lock, context);
> > /* socket destruction will be done on close() */
> > +   rtdm_nrtsig_pend(>close_sig);
> > goto drop;
> > } else if (ts->tcp_state == TCP_FIN_WAIT1) {
> > ts->tcp_state = TCP_FIN_WAIT2;
> > @@ -1119,6 +1124,7 @@ static void rt_tcp_rcv(struct rtskb *skb)
> > ts->tcp_state = TCP_TIME_WAIT;
> > rtdm_lock_put_irqrestore(>socket_lock, context);
> > /* socket destruction will be done on close() */
> > +   rtdm_nrtsig_pend(>close_sig);
> > goto feed;
> > }
> > }
> > @@ -1190,6 +1196,11 @@ static int rt_tcp_window_send(struct tcp_socket *ts, 
> > u32 data_len, u8 *data_ptr)
> > return ret;
> >   }
> >
> > +static void rt_tcp_close_signal_handler(rtdm_nrtsig_t *nrtsig, void *arg)
> > +{
> > +   up((struct semaphore *)arg);
> > +}
> > +
> >   static int rt_tcp_socket_create(struct tcp_socket *ts)
> >   {
> > rtdm_lockctx_t context;
> > @@ -1226,6 +1237,10 @@ static int rt_tcp_socket_create(struct tcp_socket 
> > *ts)
> > timerwheel_init_timer(>timer, rt_tcp_retransmit_handler, ts);
> > rtskb_queue_init(>retransmit_queue);
> >
> > +   sema_init(>close_sem, 0);
> > +   rtdm_nrtsig_init(>close_sig, rt_tcp_close_signal_handler,
> > +>close_sem);
> > +
> >   #ifdef CONFIG_XENO_DRIVERS_NET_RTIPV4_TCP_ERROR_INJECTION
> > ts->packet_counter = counter_start;
> > ts->error_rate = error_rate;
> > @@ -1237,6 +1252,7 @@ static int rt_tcp_socket_create(struct tcp_socket *ts)
> > /* enforce maximum number of TCP sockets */
> > if (free_ports == 0) {
> > rtdm_lock_put_irqrestore(_socket_base_lock, context);
> > +   rtdm_nrtsig_destroy(>close_sig);
> > return -EAGAIN;
> > }
> > free_ports--;
> > @@ -1338,6 +1354,8 @@ static void rt_tcp_socket_destruct(struct tcp_socket 
> > *ts)
> >
> > rtdm_event_destroy(>conn_evt);
> >
> > +   rtdm_nrtsig_destroy(>close_sig);
> > +
> > /* cleanup already collected fragments */
> > rt_ip_frag_invalidate_socket(sock);
> >
> > @@ -1362,6 +1380,7 @@ static void rt_tcp_close(struct rtdm_fd *fd)
&g

[PATCH] net/tcp: Account for connection teardown handshake

2019-09-17 Thread Sebastian Smolorz via Xenomai
When closing a TCP connection a handshake procedure is executed between the
peers. The close routine of the rttcp driver did not participate in
detecting the end of this handshake but rather waited one second inside
a close call unconditionally. Especially when peers are directly connected
this is a waste of time which can hurt a lot in some situations.

This patch replaces the msleep(1000) call with a timed wait on a
semaphore which gets sigalled when the termination handshake is complete.

Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 29 +++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index 54bafa80f..81089afd1 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -147,6 +147,9 @@ struct tcp_socket {
struct rtskb_queue retransmit_queue;
struct timerwheel_timer timer;

+   struct semaphore close_sem;
+   rtdm_nrtsig_t close_sig;
+
 #ifdef CONFIG_XENO_DRIVERS_NET_RTIPV4_TCP_ERROR_INJECTION
unsigned int packet_counter;
unsigned int error_rate;
@@ -1042,6 +1045,7 @@ static void rt_tcp_rcv(struct rtskb *skb)
rt_tcp_send(ts, TCP_FLAG_ACK);
/* data receiving is not possible anymore */
rtdm_sem_destroy(>sock.pending_sem);
+   rtdm_nrtsig_pend(>close_sig);
goto feed;
} else if (ts->tcp_state == TCP_FIN_WAIT1) {
/* Send ACK */
@@ -1105,6 +1109,7 @@ static void rt_tcp_rcv(struct rtskb *skb)
ts->tcp_state = TCP_CLOSE;
rtdm_lock_put_irqrestore(>socket_lock, context);
/* socket destruction will be done on close() */
+   rtdm_nrtsig_pend(>close_sig);
goto drop;
} else if (ts->tcp_state == TCP_FIN_WAIT1) {
ts->tcp_state = TCP_FIN_WAIT2;
@@ -1119,6 +1124,7 @@ static void rt_tcp_rcv(struct rtskb *skb)
ts->tcp_state = TCP_TIME_WAIT;
rtdm_lock_put_irqrestore(>socket_lock, context);
/* socket destruction will be done on close() */
+   rtdm_nrtsig_pend(>close_sig);
goto feed;
}
}
@@ -1190,6 +1196,11 @@ static int rt_tcp_window_send(struct tcp_socket *ts, u32 
data_len, u8 *data_ptr)
return ret;
 }

+static void rt_tcp_close_signal_handler(rtdm_nrtsig_t *nrtsig, void *arg)
+{
+   up((struct semaphore *)arg);
+}
+
 static int rt_tcp_socket_create(struct tcp_socket *ts)
 {
rtdm_lockctx_t context;
@@ -1226,6 +1237,10 @@ static int rt_tcp_socket_create(struct tcp_socket *ts)
timerwheel_init_timer(>timer, rt_tcp_retransmit_handler, ts);
rtskb_queue_init(>retransmit_queue);

+   sema_init(>close_sem, 0);
+   rtdm_nrtsig_init(>close_sig, rt_tcp_close_signal_handler,
+>close_sem);
+
 #ifdef CONFIG_XENO_DRIVERS_NET_RTIPV4_TCP_ERROR_INJECTION
ts->packet_counter = counter_start;
ts->error_rate = error_rate;
@@ -1237,6 +1252,7 @@ static int rt_tcp_socket_create(struct tcp_socket *ts)
/* enforce maximum number of TCP sockets */
if (free_ports == 0) {
rtdm_lock_put_irqrestore(_socket_base_lock, context);
+   rtdm_nrtsig_destroy(>close_sig);
return -EAGAIN;
}
free_ports--;
@@ -1338,6 +1354,8 @@ static void rt_tcp_socket_destruct(struct tcp_socket *ts)

rtdm_event_destroy(>conn_evt);

+   rtdm_nrtsig_destroy(>close_sig);
+
/* cleanup already collected fragments */
rt_ip_frag_invalidate_socket(sock);

@@ -1362,6 +1380,7 @@ static void rt_tcp_close(struct rtdm_fd *fd)
struct rt_tcp_dispatched_packet_send_cmd send_cmd;
rtdm_lockctx_t context;
int signal = 0;
+   int ret;

rtdm_lock_get_irqsave(>socket_lock, context);

@@ -1380,7 +1399,10 @@ static void rt_tcp_close(struct rtdm_fd *fd)
/* result is ignored */

/* Give the peer some time to reply to our FIN. */
-   msleep(1000);
+   ret = down_timeout(>close_sem, msecs_to_jiffies(1000));
+   if (ret)
+   rtdm_printk("rttcp: waiting for FIN-ACK handshake 
returned %d\n",
+   ret);
} else if (ts->tcp_state == TCP_CLOSE_WAIT) {
/* Send FIN in CLOSE_WAIT */
send_cmd.ts = ts;
@@ -1394,7 +1416,10 @@ static void rt_tcp_close(struct rtdm_fd *fd)
/* result is ignored */

/* Give the peer some time to reply to our F

Re: Finalizing 3.1, finally

2019-09-13 Thread Sebastian Smolorz via Xenomai
Hi Jan,

Jan Kiszka wrote:
> we are postponing this for too long now, so I'd like to make step towards a
> feature freeze for 3.1, marked by an -rc1, and then a release. So, everyone
> sitting on API- or even ABI-breaking changes should speak up now.

This week I have improved the close behaviour of the rttcp driver but want
to make some more tests in the next week before I post a patch. When do
you plan to release -rc1?

--
Sebastian




[PATCH] net/ip_sock: ioctl: fix unsafe accesses from/to userspace

2019-06-06 Thread Sebastian Smolorz via Xenomai
Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/ip_sock.c | 127 
 1 file changed, 88 insertions(+), 39 deletions(-)

diff --git a/kernel/drivers/net/stack/ipv4/ip_sock.c 
b/kernel/drivers/net/stack/ipv4/ip_sock.c
index 20f27feff..1ae3a9eeb 100644
--- a/kernel/drivers/net/stack/ipv4/ip_sock.c
+++ b/kernel/drivers/net/stack/ipv4/ip_sock.c
@@ -4,6 +4,7 @@
  *
  *  Copyright (C) 2003   Hans-Peter Bock 
  *2004, 2005 Jan Kiszka 
+ *2019   Sebastian Smolorz 
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -28,11 +29,11 @@
 #include 


-int rt_ip_setsockopt(struct rtsocket *s, int level, int optname,
-const void *optval, socklen_t optlen)
+int rt_ip_setsockopt(struct rtdm_fd *fd, struct rtsocket *s, int level,
+int optname, const void __user *optval, socklen_t optlen)
 {
 int err = 0;
-
+unsigned int _tos, *tos;

 if (level != SOL_IP)
return -ENOPROTOOPT;
@@ -42,7 +43,11 @@ int rt_ip_setsockopt(struct rtsocket *s, int level, int 
optname,

 switch (optname) {
case IP_TOS:
-   s->prot.inet.tos = *(unsigned int *)optval;
+   tos = rtnet_get_arg(fd, &_tos, optval, sizeof(_tos));
+   if (IS_ERR(tos))
+   return PTR_ERR(tos);
+   else
+   s->prot.inet.tos = *tos;
break;

default:
@@ -55,19 +60,29 @@ int rt_ip_setsockopt(struct rtsocket *s, int level, int 
optname,



-int rt_ip_getsockopt(struct rtsocket *s, int level, int optname,
-void *optval, socklen_t *optlen)
+int rt_ip_getsockopt(struct rtdm_fd *fd, struct rtsocket *s, int level,
+int optname, void __user *optval,
+socklen_t __user *optlen)
 {
 int err = 0;
+unsigned int tos;
+socklen_t _len, *len;

+len = rtnet_get_arg(fd, &_len, optlen, sizeof(_len));
+if (IS_ERR(len))
+   return PTR_ERR(len);

-if (*optlen < sizeof(unsigned int))
+if (*len < sizeof(unsigned int))
return -EINVAL;

 switch (optname) {
case IP_TOS:
-   *(unsigned int *)optval = s->prot.inet.tos;
-   *optlen = sizeof(unsigned int);
+   tos = s->prot.inet.tos;
+   err = rtnet_put_arg(fd, optval, , sizeof(tos));
+   if (!err) {
+   *len = sizeof(unsigned int);
+   err = rtnet_put_arg(fd, optlen, len, sizeof(socklen_t));
+   }
break;

default:
@@ -80,72 +95,106 @@ int rt_ip_getsockopt(struct rtsocket *s, int level, int 
optname,



-int rt_ip_getsockname(struct rtsocket *s, struct sockaddr *addr,
- socklen_t *addrlen)
+int rt_ip_getsockname(struct rtdm_fd *fd, struct rtsocket *s,
+ struct sockaddr __user *addr,
+ socklen_t __user *addrlen)
 {
-struct sockaddr_in *usin = (struct sockaddr_in *)addr;
+struct sockaddr_in _sin;
+socklen_t *len, _len;
+int ret;

+len = rtnet_get_arg(fd, &_len, addrlen, sizeof(_len));
+if (IS_ERR(len))
+   return PTR_ERR(len);

-if (*addrlen < sizeof(struct sockaddr_in))
+if (*len < sizeof(struct sockaddr_in))
return -EINVAL;

-usin->sin_family  = AF_INET;
-usin->sin_addr.s_addr = s->prot.inet.saddr;
-usin->sin_port= s->prot.inet.sport;
-
-memset(usin->sin_zero, 0, sizeof(usin->sin_zero));
+_sin.sin_family  = AF_INET;
+_sin.sin_addr.s_addr = s->prot.inet.saddr;
+_sin.sin_port= s->prot.inet.sport;
+memset(&_sin.sin_zero, 0, sizeof(_sin.sin_zero));
+ret = rtnet_put_arg(fd, addr, &_sin, sizeof(_sin));
+if (ret)
+   return ret;

-*addrlen = sizeof(struct sockaddr_in);
+*len = sizeof(struct sockaddr_in);
+ret = rtnet_put_arg(fd, addrlen, len, sizeof(socklen_t));

-return 0;
+return ret;
 }



-int rt_ip_getpeername(struct rtsocket *s, struct sockaddr *addr,
- socklen_t *addrlen)
+int rt_ip_getpeername(struct rtdm_fd *fd, struct rtsocket *s,
+ struct sockaddr __user *addr,
+ socklen_t __user *addrlen)
 {
-struct sockaddr_in *usin = (struct sockaddr_in *)addr;
+struct sockaddr_in _sin;
+socklen_t *len, _len;
+int ret;

+len = rtnet_get_arg(fd, &_len, addrlen, sizeof(_len));
+if (IS_ERR(len))
+   return PTR_ERR(len);

-if (*addrlen < sizeof(struct sockaddr_in))
+if (*len < sizeof(struct sockaddr_in))
return -EINVAL;

-usin->sin_family  = AF_INET;
-usin->sin_addr.s_addr = s->prot.inet.daddr;
-usin->sin_port= s->prot.inet.dport;
+_sin.sin_family  = AF_INET;
+_sin.sin_addr.s_addr = s->prot.inet.daddr;
+_sin.si

Re: RTnet bind failed socket again

2019-06-04 Thread Sebastian Smolorz via Xenomai
Hi,

on 04.06.2019 09:45, Per Oberg wrote:
> - Den 3 jun 2019, på kl 17:33, Jan Kiszka jan.kis...@siemens.com skrev:
> 
> > On 03.06.19 11:10, Per Oberg via Xenomai wrote:
> 
> 
> 
> > > - Den 3 jun 2019, på kl 11:06, xenomai xenomai@xenomai.org skrev:
> 
> > >> Hi,
> 
> > >> My program opens a RTnet socket successfully but the program gets killed
> > >> by a different issue that has nothing to do with this. However, the
> > >> RTnet socket is still bound. If I try to start the program again i get
> > >> the error "Address already in use". If it would be a normal unix socket
> > >> I would simply call it with SO_REUSEADDR but this is not possible with
> > >> RTnet from what I understand.
> 
> >> I tried this and failed miserably. That said, I'm also interested in the 
> >> answer
> > > to this question.
> 
> > >> My question is why the socket is not unbound after the binding process
> > >> is killed and if there is a way to reclaim this socket. By the way, it
> > >> has to be this socket since the communication partner expects the server
> > >> to listen on this exact port.
> 
> > >> Cheers,
> 
> > >> Johannes
> 
> > > Per Öberg
> 
> 
> > Are we talking about UDP in both cases?
> 
> I use UDP, yes. But I had no problems with the UDP part. 
> 
> The problem I had was regarding the use of setsockopt. Because I test the 
> code on a regular linux machine the lingering of the sockets after killing 
> the application can be annoying. From what you describe below, SO_REUSEADDR 
> should not be necessary for this case (did I get that correctly? ). 
> 
> Because I use the posix skin, and because it was necessary in regular linux, 
> i started out using it in the common code base but I never managed to get it 
> working in RT so I removed it again. 
> 
> I used something like:
> 
> > int reuseSetting = 1;
> > setsockopt(datagramSocket, SOL_SOCKET, SO_REUSEADDR, , 
> > sizeof(int);
> 
> Or even (because I use both rt and not rt sockets in the same code and I got 
> the feeling that the automatic handling of this didn't quite work out.)
> > __cobalt_setsockopt(datagramSocket, SOL_SOCKET, SO_REUSEADDR, 
> > , sizeof(int);
> 
> 
> This gave me: 
> --
> 70642.91] [Xenomai] switching App Thread to secondary mode after 
> exception #14 in kernel-space at 0xa0281787 (pid 633)
> [70642.667326] BUG: unable to handle kernel paging request at 7fe06ff84d20
> [70642.667948] IP: [] rt_ip_ioctl+0x27/0x120 [rtipv4]
> [70642.668566] PGD 8002631e7067 
> [70642.668575] PUD 24a07d067 
> [70642.669184] PMD 260cab067 
> [70642.669189] PTE 80023b6cc067
> [70642.669805] 
> [70642.670403] Oops: 0001 [#5] PREEMPT SMP
> [70642.670989] Modules linked in: rtudp rtipv4 intel_powerclamp intel_rapl 
> coretemp rt_igb e1000e i915 rtnet pcan(O) video fan thermal_sys
> [70642.671629] CPU: 3 PID: 633 Comm: App Thread Tainted: G  D W  O
> 4.9.90-xeno-cobolt #1
> [70642.672239] Hardware name: Default string Default string/SKYBAY, BIOS 
> 5.0.1.1 04/18/2016
> [70642.672854] I-pipe domain: Linux
> [70642.673459] task: 880263231b00 task.stack: c90001798000
> [70642.674066] RIP: 0010:[]  [] 
> rt_ip_ioctl+0x27/0x120 [rtipv4]
> [70642.674683] RSP: 0018:c9000179bda8  EFLAGS: 00010246
> [70642.675300] RAX: 0007 RBX: 40180021 RCX: 
> 88026dd8
> [70642.675923] RDX: 7fe06ff84d20 RSI: 40180021 RDI: 
> 880262a86800
> [70642.676544] RBP: c9000179bdd0 R08: 0050 R09: 
> 880263231b00
> [70642.677166] R10: 00e6 R11:  R12: 
> 880262a86800
> [70642.677783] R13: 40180021 R14: 7fe06ff84d20 R15: 
> 62a86800
> [70642.678394] FS:  7fe06ff85700() GS:88026dd8() 
> knlGS:
> [70642.679009] CS:  0010 DS:  ES:  CR0: 8005003b
> [70642.679621] CR2: 7fe06ff84d20 CR3: 000261678000 CR4: 
> 00360630
> [70642.680233] Stack:
> [70642.680838]  a028c6f7 0001 81178cd0 
> 880262a86800
> [70642.681464]  0003 c9000179be60 811725be 
> 0202
> [70642.682086]  880263231b00 88020010 c9000179be70 
> c9000179be08
> [70642.682711] Call Trace:
> [70642.683325]  [] ? rt_udp_ioctl+0x67/0x8c [rtudp]
> [70642.683949]  [] ? CoBaLt_fcntl+0x20/0x20
> [70642.684573]  [] rtdm_fd_ioctl+0xee/0x280
> [70642.685199]  [] ? CoBaLt_fcntl+0x20/0x20
> [70642.685825]  [] ? CoBaLt_fcntl+0x20/0x20
> [70642.686445]  [] CoBaLt_ioctl+0xe/0x20
> [70642.687064]  [] ipipe_syscall_hook+0x112/0x350
> [70642.687686]  [] __ipipe_notify_syscall+0xc8/0x190
> [70642.688306]  [] ipipe_handle_syscall+0x2a/0xb0
> [70642.688925]  [] do_syscall_64+0x2d/0xf0
> [70642.689514]  [] entry_SYSCALL_64_after_swapgs+0x58/0xc6
> [70642.690073] Code: 68 b8 eb b0 e8 ab 04 66 e1 81 fe 27 00 10 40 0f 84 c1 00 
> 00 00 7e 73 

[PATCH v2] net/tcp: fix unsafe accesses from/to userspace

2019-06-03 Thread Sebastian Smolorz via Xenomai
Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 90 -
 1 file changed, 59 insertions(+), 31 deletions(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index 828f7d115..f4ea6ffcc 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -1418,15 +1418,18 @@ static void rt_tcp_close(struct rtdm_fd *fd)
  *  @s: socket
  *  @addr:  local address
  */
-static int rt_tcp_bind(struct tcp_socket *ts, const struct sockaddr *addr,
-  socklen_t addrlen)
+static int rt_tcp_bind(struct rtdm_fd *fd, struct tcp_socket *ts,
+  const struct sockaddr __user *addr, socklen_t addrlen)
 {
-struct sockaddr_in  *usin = (struct sockaddr_in *)addr;
+struct sockaddr_in  *usin, _usin;
 rtdm_lockctx_t  context;
 int index;
 int bound = 0;
 int ret = 0;

+usin = rtnet_get_arg(fd, &_usin, addr, sizeof(_usin));
+if (IS_ERR(usin))
+   return PTR_ERR(usin);

 if ((addrlen < (int)sizeof(struct sockaddr_in)) ||
((usin->sin_port & tcp_auto_port_mask) == tcp_auto_port_start))
@@ -1475,10 +1478,11 @@ static int rt_tcp_bind(struct tcp_socket *ts, const 
struct sockaddr *addr,
 /***
  *  rt_tcp_connect
  */
-static int rt_tcp_connect(struct tcp_socket *ts, const struct sockaddr 
*serv_addr,
+static int rt_tcp_connect(struct rtdm_fd *fd, struct tcp_socket *ts,
+ const struct sockaddr __user *serv_addr,
  socklen_t addrlen)
 {
-struct sockaddr_in  *usin = (struct sockaddr_in *) serv_addr;
+struct sockaddr_in  *usin, _usin;
 struct dest_route   rt;
 rtdm_lockctx_t  context;
 int ret;
@@ -1486,6 +1490,10 @@ static int rt_tcp_connect(struct tcp_socket *ts, const 
struct sockaddr *serv_add
 if (addrlen < (int)sizeof(struct sockaddr_in))
return -EINVAL;

+usin = rtnet_get_arg(fd, &_usin, serv_addr, sizeof(_usin));
+if (IS_ERR(usin))
+   return PTR_ERR(usin);
+
 if (usin->sin_family != AF_INET)
return -EAFNOSUPPORT;

@@ -1594,18 +1602,23 @@ static int rt_tcp_listen(struct tcp_socket *ts, 
unsigned long backlog)
 /***
  *  rt_tcp_accept
  */
-static int rt_tcp_accept(struct tcp_socket *ts, struct sockaddr *addr,
-socklen_t *addrlen)
+static int rt_tcp_accept(struct rtdm_fd *fd, struct tcp_socket *ts,
+struct sockaddr *addr, socklen_t __user *addrlen)
 {
 /* Return sockaddr, but bind it with rt_socket_init, so it would be
possible to read/write from it in future, return valid file descriptor 
*/

 int ret;
-struct sockaddr_in  *sin = (struct sockaddr_in*)addr;
+socklen_t   *uaddrlen, _uaddrlen;
+struct sockaddr_in  sin;
 nanosecs_rel_t  timeout = ts->sock.timeout;
 rtdm_lockctx_t  context;
 struct dest_route   rt;

+uaddrlen = rtnet_get_arg(fd, &_uaddrlen, addrlen, sizeof(_uaddrlen));
+if (IS_ERR(uaddrlen))
+   return PTR_ERR(uaddrlen);
+
 rtdm_lock_get_irqsave(>socket_lock, context);
 if (ts->is_accepting || ts->is_accepted) {
/* socket is already accepted or is accepting a connection right now */
@@ -1613,7 +1626,7 @@ static int rt_tcp_accept(struct tcp_socket *ts, struct 
sockaddr *addr,
return -EALREADY;
 }

-if (ts->tcp_state != TCP_LISTEN || *addrlen < sizeof(struct sockaddr_in)) {
+if (ts->tcp_state != TCP_LISTEN || *uaddrlen < sizeof(struct sockaddr_in)) 
{
rtdm_lock_put_irqrestore(>socket_lock, context);
return -EINVAL;
 }
@@ -1642,6 +1655,18 @@ static int rt_tcp_accept(struct tcp_socket *ts, struct 
sockaddr *addr,
goto err;
 }

+if (addr) {
+   sin.sin_family  = AF_INET;
+   sin.sin_port= ts->dport;
+   sin.sin_addr.s_addr = ts->daddr;
+   ret = rtnet_put_arg(fd, addr, , sizeof(sin));
+   if (ret) {
+   rtdev_dereference(rt.rtdev);
+   ret = -EFAULT;
+   goto err;
+   }
+}
+
 rtdm_lock_get_irqsave(>socket_lock, context);

 if (ts->tcp_state != TCP_ESTABLISHED) {
@@ -1657,10 +1682,6 @@ static int rt_tcp_accept(struct tcp_socket *ts, struct 
sockaddr *addr,
 else
rtdev_dereference(rt.rtdev);

-sin->sin_family  = AF_INET;
-sin->sin_port= ts->dport;
-sin->sin_addr.s_addr = ts->daddr;
-
 ts->is_accepted = 1;
 rtdm_lock_put_irqrestore(>socket_lock, context);

@@ -1799,14 +1820,14 @@ static int rt_tcp_ioctl(struct rtdm_fd *fd,
setaddr = rtnet_get_arg(fd, &_setaddr, arg, sizeof(_setaddr));
if (IS_ERR(setaddr))
return PTR_ERR(setaddr);
-   return rt_tcp_bind(ts, setaddr->addr, setaddr->a

Re: [PATCH] net/tcp: fix unsafe accesses from/to userspace

2019-06-01 Thread Sebastian Smolorz via Xenomai
Hi Jan,

On 29.05.19 19:17, Jan Kiszka wrote:
> On 28.05.19 16:05, Sebastian Smolorz wrote:
> > Signed-off-by: Sebastian Smolorz 
> > ---
> >   kernel/drivers/net/stack/ipv4/tcp/tcp.c | 91 -
> >   1 file changed, 60 insertions(+), 31 deletions(-)
> >
> > diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
> > b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
> > index 828f7d115..4803165f4 100644
> > --- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
> > +++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
> > @@ -1418,15 +1418,18 @@ static void rt_tcp_close(struct rtdm_fd *fd)
> >*  @s: socket
> >*  @addr:  local address
> >*/
> > -static int rt_tcp_bind(struct tcp_socket *ts, const struct sockaddr *addr,
> > -  socklen_t addrlen)
> > +static int rt_tcp_bind(struct rtdm_fd *fd, struct tcp_socket *ts,
> > +  const struct sockaddr __user *addr, socklen_t addrlen)
> >   {
> > -struct sockaddr_in  *usin = (struct sockaddr_in *)addr;
> > +struct sockaddr_in  *usin, _usin;
> >   rtdm_lockctx_t  context;
> >   int index;
> >   int bound = 0;
> >   int ret = 0;
> >
> > +usin = rtnet_get_arg(fd, &_usin, addr, sizeof(_usin));
> > +if (IS_ERR(usin))
> > +   return PTR_ERR(usin);
> >
> >   if ((addrlen < (int)sizeof(struct sockaddr_in)) ||
> > ((usin->sin_port & tcp_auto_port_mask) == tcp_auto_port_start))
> > @@ -1475,10 +1478,11 @@ static int rt_tcp_bind(struct tcp_socket *ts, const 
> > struct sockaddr *addr,
> >   /***
> >*  rt_tcp_connect
> >*/
> > -static int rt_tcp_connect(struct tcp_socket *ts, const struct sockaddr 
> > *serv_addr,
> > +static int rt_tcp_connect(struct rtdm_fd *fd, struct tcp_socket *ts,
> > + const struct sockaddr __user *serv_addr,
> >   socklen_t addrlen)
> >   {
> > -struct sockaddr_in  *usin = (struct sockaddr_in *) serv_addr;
> > +struct sockaddr_in  *usin, _usin;
> >   struct dest_route   rt;
> >   rtdm_lockctx_t  context;
> >   int ret;
> > @@ -1486,6 +1490,10 @@ static int rt_tcp_connect(struct tcp_socket *ts, 
> > const struct sockaddr *serv_add
> >   if (addrlen < (int)sizeof(struct sockaddr_in))
> > return -EINVAL;
> >
> > +usin = rtnet_get_arg(fd, &_usin, serv_addr, sizeof(_usin));
> > +if (IS_ERR(usin))
> > +   return PTR_ERR(usin);
> > +
> >   if (usin->sin_family != AF_INET)
> > return -EAFNOSUPPORT;
> >
> > @@ -1594,18 +1602,23 @@ static int rt_tcp_listen(struct tcp_socket *ts, 
> > unsigned long backlog)
> >   /***
> >*  rt_tcp_accept
> >*/
> > -static int rt_tcp_accept(struct tcp_socket *ts, struct sockaddr *addr,
> > -socklen_t *addrlen)
> > +static int rt_tcp_accept(struct rtdm_fd *fd, struct tcp_socket *ts,
> > +struct sockaddr *addr, socklen_t __user *addrlen)
> >   {
> >   /* Return sockaddr, but bind it with rt_socket_init, so it would be
> >  possible to read/write from it in future, return valid file 
> > descriptor */
> >
> >   int ret;
> > -struct sockaddr_in  *sin = (struct sockaddr_in*)addr;
> > +socklen_t   *uaddrlen, _uaddrlen;
> > +struct sockaddr_in  sin;
> >   nanosecs_rel_t  timeout = ts->sock.timeout;
> >   rtdm_lockctx_t  context;
> >   struct dest_route   rt;
> >
> > +uaddrlen = rtnet_get_arg(fd, &_uaddrlen, addrlen, sizeof(_uaddrlen));
> > +if (IS_ERR(uaddrlen))
> > +   return PTR_ERR(uaddrlen);
> > +
> >   rtdm_lock_get_irqsave(>socket_lock, context);
> >   if (ts->is_accepting || ts->is_accepted) {
> > /* socket is already accepted or is accepting a connection right now */
> > @@ -1613,7 +1626,7 @@ static int rt_tcp_accept(struct tcp_socket *ts, 
> > struct sockaddr *addr,
> > return -EALREADY;
> >   }
> >
> > -if (ts->tcp_state != TCP_LISTEN || *addrlen < sizeof(struct 
> > sockaddr_in)) {
> > +if (ts->tcp_state != TCP_LISTEN || *uaddrlen < sizeof(struct 
> > sockaddr_in)) {
> > rtdm_lock_put_irqrestore(>socket_lock, context);
> > return -EINVAL;
> >   }
> > @@ -1652,15 +1665,24 @@ static int rt_tcp_accept(struct tcp_socket *ts, 
> > struct sockaddr *addr,
> > goto err;
>

[PATCH] net/tcp: fix unsafe accesses from/to userspace

2019-05-28 Thread Sebastian Smolorz via Xenomai
Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 91 -
 1 file changed, 60 insertions(+), 31 deletions(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index 828f7d115..4803165f4 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -1418,15 +1418,18 @@ static void rt_tcp_close(struct rtdm_fd *fd)
  *  @s: socket
  *  @addr:  local address
  */
-static int rt_tcp_bind(struct tcp_socket *ts, const struct sockaddr *addr,
-  socklen_t addrlen)
+static int rt_tcp_bind(struct rtdm_fd *fd, struct tcp_socket *ts,
+  const struct sockaddr __user *addr, socklen_t addrlen)
 {
-struct sockaddr_in  *usin = (struct sockaddr_in *)addr;
+struct sockaddr_in  *usin, _usin;
 rtdm_lockctx_t  context;
 int index;
 int bound = 0;
 int ret = 0;

+usin = rtnet_get_arg(fd, &_usin, addr, sizeof(_usin));
+if (IS_ERR(usin))
+   return PTR_ERR(usin);

 if ((addrlen < (int)sizeof(struct sockaddr_in)) ||
((usin->sin_port & tcp_auto_port_mask) == tcp_auto_port_start))
@@ -1475,10 +1478,11 @@ static int rt_tcp_bind(struct tcp_socket *ts, const 
struct sockaddr *addr,
 /***
  *  rt_tcp_connect
  */
-static int rt_tcp_connect(struct tcp_socket *ts, const struct sockaddr 
*serv_addr,
+static int rt_tcp_connect(struct rtdm_fd *fd, struct tcp_socket *ts,
+ const struct sockaddr __user *serv_addr,
  socklen_t addrlen)
 {
-struct sockaddr_in  *usin = (struct sockaddr_in *) serv_addr;
+struct sockaddr_in  *usin, _usin;
 struct dest_route   rt;
 rtdm_lockctx_t  context;
 int ret;
@@ -1486,6 +1490,10 @@ static int rt_tcp_connect(struct tcp_socket *ts, const 
struct sockaddr *serv_add
 if (addrlen < (int)sizeof(struct sockaddr_in))
return -EINVAL;

+usin = rtnet_get_arg(fd, &_usin, serv_addr, sizeof(_usin));
+if (IS_ERR(usin))
+   return PTR_ERR(usin);
+
 if (usin->sin_family != AF_INET)
return -EAFNOSUPPORT;

@@ -1594,18 +1602,23 @@ static int rt_tcp_listen(struct tcp_socket *ts, 
unsigned long backlog)
 /***
  *  rt_tcp_accept
  */
-static int rt_tcp_accept(struct tcp_socket *ts, struct sockaddr *addr,
-socklen_t *addrlen)
+static int rt_tcp_accept(struct rtdm_fd *fd, struct tcp_socket *ts,
+struct sockaddr *addr, socklen_t __user *addrlen)
 {
 /* Return sockaddr, but bind it with rt_socket_init, so it would be
possible to read/write from it in future, return valid file descriptor 
*/

 int ret;
-struct sockaddr_in  *sin = (struct sockaddr_in*)addr;
+socklen_t   *uaddrlen, _uaddrlen;
+struct sockaddr_in  sin;
 nanosecs_rel_t  timeout = ts->sock.timeout;
 rtdm_lockctx_t  context;
 struct dest_route   rt;

+uaddrlen = rtnet_get_arg(fd, &_uaddrlen, addrlen, sizeof(_uaddrlen));
+if (IS_ERR(uaddrlen))
+   return PTR_ERR(uaddrlen);
+
 rtdm_lock_get_irqsave(>socket_lock, context);
 if (ts->is_accepting || ts->is_accepted) {
/* socket is already accepted or is accepting a connection right now */
@@ -1613,7 +1626,7 @@ static int rt_tcp_accept(struct tcp_socket *ts, struct 
sockaddr *addr,
return -EALREADY;
 }

-if (ts->tcp_state != TCP_LISTEN || *addrlen < sizeof(struct sockaddr_in)) {
+if (ts->tcp_state != TCP_LISTEN || *uaddrlen < sizeof(struct sockaddr_in)) 
{
rtdm_lock_put_irqrestore(>socket_lock, context);
return -EINVAL;
 }
@@ -1652,15 +1665,24 @@ static int rt_tcp_accept(struct tcp_socket *ts, struct 
sockaddr *addr,
goto err;
 }

+if (addr) {
+   sin.sin_family  = AF_INET;
+   sin.sin_port= ts->dport;
+   sin.sin_addr.s_addr = ts->daddr;
+   ret = rtnet_put_arg(fd, addr, , sizeof(sin));
+   if (ret) {
+   rtdm_lock_put_irqrestore(>socket_lock, context);
+   rtdev_dereference(rt.rtdev);
+   ret = -EFAULT;
+   goto err;
+   }
+}
+
 if (ts->rt.rtdev == NULL)
memcpy(>rt, , sizeof(rt));
 else
rtdev_dereference(rt.rtdev);

-sin->sin_family  = AF_INET;
-sin->sin_port= ts->dport;
-sin->sin_addr.s_addr = ts->daddr;
-
 ts->is_accepted = 1;
 rtdm_lock_put_irqrestore(>socket_lock, context);

@@ -1799,14 +1821,14 @@ static int rt_tcp_ioctl(struct rtdm_fd *fd,
setaddr = rtnet_get_arg(fd, &_setaddr, arg, sizeof(_setaddr));
if (IS_ERR(setaddr))
return PTR_ERR(setaddr);
-   return rt_tcp_bind(ts, setaddr->addr, setaddr->addrlen);
+   return rt_tcp_b

Re: [PATCH v2 4/8] net/tcp: Copy data back to user buffer in rt_tcp_recvmsg

2018-11-08 Thread Sebastian Smolorz via Xenomai
On 06.11.18, 19:52, Jan Kiszka wrote:
> On 06.11.18 11:00, Sebastian Smolorz via Xenomai wrote:
> > A bug in rt_tcp_recvmsg() prevented an application to receive data
> > over an RTTCP socket. Data was not copied back to the application's
> > buffer but rather into a temporary kernel buffer.
> > 
> > Signed-off-by: Sebastian Smolorz 
> > ---
> > 
> >  kernel/drivers/net/stack/ipv4/tcp/tcp.c | 13 +++--
> >  1 file changed, 3 insertions(+), 10 deletions(-)
> > 
> > diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
> > b/kernel/drivers/net/stack/ipv4/tcp/tcp.c index 2678e6a..3242a08
> > 100644
> > --- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
> > +++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
> > @@ -2084,17 +2084,10 @@ static ssize_t rt_tcp_recvmsg(struct rtdm_fd
> > *fd, struct user_msghdr *msg, int m> 
> > len = iov[0].iov_len;
> > if (len > 0) {
> > 
> > -   buf = xnmalloc(len);
> > -   if (buf == NULL) {
> > -   ret = -ENOMEM;
> > -   goto out;
> > -   }
> > -   ret = rtdm_copy_from_user(fd, buf, iov[0].iov_base, len);
> > -   if (!ret)
> > -   ret = rt_tcp_read(fd, buf, len);
> > -   xnfree(buf);
> > +   buf = iov[0].iov_base;
> > +   ret = rt_tcp_read(fd, buf, len);
> 
> Does this go well with smap? IOW: Was everything testing on a system
> with smap support available and enabled?

smap was enabled. Tests were executed on an Atom E3845. cat /proc/
cpuinfo showed no smap flag.

> > }
> > 
> > -out:
> > +
> > 
> > rtdm_drop_iovec(iov, iov_fast);
> > 
> > return ret;

-- 
Sebastian






Re: [PATCH 0/4] net/tcp: Fix several bugs and allow rttcp to be built

2018-11-06 Thread Sebastian Smolorz via Xenomai
Hi Phong,

Pham, Phong wrote:
> Hi Sebastian,
>
> Your patch (fixing TCP flags endianness issue) does work.

Great, thanks for testing.

--
Sebastian

> (I was
> under the impression to use tcp_flag_word and fix it in
> rt_tcp_set_flags() which I reported doesn't work earlier.)

> Phong.
>
> -Original Message-
> From: Sebastian Smolorz [mailto:sebastian.smol...@gmx.de]
> Sent: Monday, November 05, 2018 10:38 AM
> To: Pham, Phong
> Cc: Jan Kiszka; Hillman, Robert; xenomai@xenomai.org
> Subject: Re: [PATCH 0/4] net/tcp: Fix several bugs and allow rttcp to
> be built

> Hi,
>
> Pham, Phong wrote:
>
> > Hi Sebastian,
> >
> >
> >
> > " Phong, can you test this on your machine?"
> > No the fix does not work.  It overwrites the window field.
>
>
> Did you try the patch I sent here?
>
> https://www.xenomai.org/pipermail/xenomai/2018-November/039831.html
>
> --
> Sebastian
> Notice: This e-mail and any files transmitted with it may contain Data
> Device Corporation's and its subsidiaries privileged and proprietary
> information. It is intended solely for the use of the individual or
> entity to whom it is addressed. If you are not the named recipient of
> this transmission, any disclosure, copying, distribution or reliance
> on the contents of this message is prohibited. If you received this
> e-mail in error, please destroy it and any attached files and notify
> me immediately.

> Click Here<http://www.ddc-web.com/Profile/EmailPrivacy.aspx> to view
> our privacy statement.







Re: [PATCH 0/4] net/tcp: Fix several bugs and allow rttcp to be built

2018-11-06 Thread Sebastian Smolorz via Xenomai
Hi Phong,

Sebastian Smolorz wrote:
> Pham, Phong wrote:
> > Hi Sebastian,
> >
> > " Phong, can you test this on your machine?"
> > No the fix does not work.  It overwrites the window field.
>
> Did you try the patch I sent here?
>
> https://www.xenomai.org/pipermail/xenomai/2018-November/039831.html

I have sent out a new patch series. You can fetch it and apply
it on top of master. This should also fix your problem of
receiving zero bytes although there was data sent.

--
Sebastian



[PATCH v2 4/8] net/tcp: Copy data back to user buffer in rt_tcp_recvmsg

2018-11-06 Thread Sebastian Smolorz via Xenomai
A bug in rt_tcp_recvmsg() prevented an application to receive data
over an RTTCP socket. Data was not copied back to the application's
buffer but rather into a temporary kernel buffer.

Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 13 +++--
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index 2678e6a..3242a08 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -2084,17 +2084,10 @@ static ssize_t rt_tcp_recvmsg(struct rtdm_fd *fd, 
struct user_msghdr *msg, int m
 
len = iov[0].iov_len;
if (len > 0) {
-   buf = xnmalloc(len);
-   if (buf == NULL) {
-   ret = -ENOMEM;
-   goto out;
-   }
-   ret = rtdm_copy_from_user(fd, buf, iov[0].iov_base, len);
-   if (!ret)
-   ret = rt_tcp_read(fd, buf, len);
-   xnfree(buf);
+   buf = iov[0].iov_base;
+   ret = rt_tcp_read(fd, buf, len);
}
-out:
+
rtdm_drop_iovec(iov, iov_fast);
 
return ret;
-- 
2.7.4




[PATCH v2 8/8] net/tcp: Allow choice of rttcp protocol in Kconfig

2018-11-06 Thread Sebastian Smolorz via Xenomai
Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/drivers/net/stack/ipv4/Kconfig 
b/kernel/drivers/net/stack/ipv4/Kconfig
index fef7e19..8fb3c1a 100644
--- a/kernel/drivers/net/stack/ipv4/Kconfig
+++ b/kernel/drivers/net/stack/ipv4/Kconfig
@@ -72,4 +72,4 @@ config XENO_DRIVERS_NET_RTIPV4_DEBUG
 may want to turn this on for tracing issues in packet delivery.
 
 source "drivers/xenomai/net/stack/ipv4/udp/Kconfig"
-# source "drivers/xenomai/net/stack/ipv4/tcp/Kconfig"
+source "drivers/xenomai/net/stack/ipv4/tcp/Kconfig"
-- 
2.7.4




[PATCH v2 2/8] net/tcp: fix listen() and shutdown() IOCTL calls

2018-11-06 Thread Sebastian Smolorz via Xenomai
listen() and shutdown() pass their simple int argument directly casted to
void *arg, not as a pointer to their value.

Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 12 ++--
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index c713635..8605a8c 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -1790,8 +1790,6 @@ static int rt_tcp_ioctl(struct rtdm_fd *fd,
 struct _rtdm_getsockopt_args _getopt;
 const struct _rtdm_setsockopt_args *setopt;
 struct _rtdm_setsockopt_args _setopt;
-const long *val;
-long _val;
 int in_rt;
 
 /* fast path for common socket IOCTLs */
@@ -1815,10 +1813,7 @@ static int rt_tcp_ioctl(struct rtdm_fd *fd,
return rt_tcp_connect(ts, setaddr->addr, setaddr->addrlen);
 
case _RTIOC_LISTEN:
-   val = rtnet_get_arg(fd, &_val, arg, sizeof(long));
-   if (IS_ERR(val))
-   return PTR_ERR(val);
-   return rt_tcp_listen(ts, *val);
+   return rt_tcp_listen(ts, (unsigned long)arg);
 
case _RTIOC_ACCEPT:
if (!in_rt)
@@ -1829,10 +1824,7 @@ static int rt_tcp_ioctl(struct rtdm_fd *fd,
return rt_tcp_accept(ts, getaddr->addr, getaddr->addrlen);
 
case _RTIOC_SHUTDOWN:
-   val = rtnet_get_arg(fd, &_val, arg, sizeof(long));
-   if (IS_ERR(val))
-   return PTR_ERR(val);
-   return rt_tcp_shutdown(ts, *val);
+   return rt_tcp_shutdown(ts, (unsigned long)arg);
 
case _RTIOC_SETSOCKOPT:
setopt = rtnet_get_arg(fd, &_setopt, arg, sizeof(_setopt));
-- 
2.7.4




[PATCH v2 6/8] net/tcp: Set valid flags in struct tcphdr on little and big endian machines

2018-11-06 Thread Sebastian Smolorz via Xenomai
Setting TCP header flags like ACK was fragile and not working when
RTnet was running on big endian processors. Use the macro provided
by the linux kernel for setting the TCP flags instead.

Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index c066e06..134469c 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -280,12 +280,6 @@ static inline int rt_tcp_after(__u32 seq1, __u32 seq2)
 return (__s32)(seq2-seq1) <= 0;
 }
 
-static inline void rt_tcp_set_flags(struct tcphdr* th, __be32 flags)
-{
-__be16 *tf = ((__be16*)th) + 6;
-*tf = flags;
-}
-
 static inline u32 rt_tcp_compute_ack_seq(struct tcphdr* th, u32 len)
 {
 u32 ack_seq = ntohl(th->seq) + len;
@@ -625,11 +619,10 @@ static void rt_tcp_build_header(struct tcp_socket *ts, 
struct rtskb *skb,
 if (unlikely(is_keepalive))
th->seq--;
 
+tcp_flag_word(th) = flags;
 th->ack_seq = htonl(ts->sync.ack_seq);
 th->window  = htons(ts->sync.window);
 
-rt_tcp_set_flags(th, flags);
-
 th->doff = tcphdrlen >> 2; /* No options for now */
 th->res1 = 0;
 th->check   = 0;
-- 
2.7.4




[PATCH v2 1/8] net/tcp: return ufd in rt_tcp_accept()

2018-11-06 Thread Sebastian Smolorz via Xenomai
Fix compilation error in rt_tcp_accept() when returning its socket's own file
descriptor.

Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index c5e42bc..c713635 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -1668,7 +1668,7 @@ static int rt_tcp_accept(struct tcp_socket *ts, struct 
sockaddr *addr,
 ts->is_accepted = 1;
 rtdm_lock_put_irqrestore(>socket_lock, context);
 
-ret = rt_socket_fd(>sock)->fd;
+ret = rtdm_fd_ufd(rt_socket_fd(>sock));
 
  err:
 /* it is not critical to leave this unlocked
-- 
2.7.4




[PATCH v2 3/8] net/tcp: Fix bug when obtaining RST socket's private structure from its rtdm_fd pointer

2018-11-06 Thread Sebastian Smolorz via Xenomai
Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index 8605a8c..2678e6a 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -182,7 +182,7 @@ static struct {
 } rst_socket_container;
 
 #define rst_fd (_socket_container.dummy.fd)
-#define rst_socket (*(struct tcp_socket *)rtdm_private_to_fd(rst_fd))
+#define rst_socket (*(struct tcp_socket *)rtdm_fd_to_private(rst_fd))
 
 static u32 tcp_auto_port_start = 1024;
 static u32 tcp_auto_port_mask  = ~(RT_TCP_SOCKETS-1);
-- 
2.7.4




[PATCH v2 0/8] net/tcp: Fix several bugs and allow rttcp to be built

2018-11-06 Thread Sebastian Smolorz via Xenomai
This patch series makes RTnet's tcp module usable again. It was not
working due to several bugs which showed up in combination with reworked
RTDM of Xenomai 3.

Tests on real hardware (little endian) were successful. A test on big
endian is still pending.

Sebastian Smolorz (8):
  net/tcp: return ufd in rt_tcp_accept()
  net/tcp: fix listen() and shutdown() IOCTL calls
  net/tcp: Fix bug when obtaining RST socket's private structure from
its rtdm_fd pointer
  net/tcp: Copy data back to user buffer in rt_tcp_recvmsg
  net/tcp: fix TCP connection termination
  net/tcp: Set valid flags in struct tcphdr on little and big endian
machines
  net/tcp: return already copied number of bytes to recv() callers when
peer socket terminates
  net/tcp: Allow choice of rttcp protocol in Kconfig

 kernel/drivers/net/stack/ipv4/Kconfig   |  2 +-
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 54 -
 2 files changed, 21 insertions(+), 35 deletions(-)

-- 
2.7.4




[PATCH v2 5/8] net/tcp: fix TCP connection termination

2018-11-06 Thread Sebastian Smolorz via Xenomai
Closing a connected TCP socket initiates a handshake procedure. The
closing socket is supposed to receive two more packets and send one
ACK at the end. RTnet's TCP stack tries to get a reference to a
socket before writing data to its buffer. Taking a reference to an
RTnet socket in Xenomai 3 is realized by calling rtdm_fd_lock() which
fails when a socket is about to be closed.

Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index 3242a08..c066e06 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -249,15 +249,18 @@ static struct rtsocket *rt_tcp_v4_lookup(u32 daddr, u16 
dport)
 {
 rtdm_lockctx_t  context;
 struct tcp_socket *ts;
+int ret;
 
 rtdm_lock_get_irqsave(_socket_base_lock, context);
 ts = port_hash_search(daddr, dport);
 
-if (ts && rt_socket_reference(>sock) == 0) {
-
-   rtdm_lock_put_irqrestore(_socket_base_lock, context);
+if (ts != NULL) {
+   ret = rt_socket_reference(>sock);
+   if (ret == 0 || (ret == -EIDRM && ts->is_closed)) {
+   rtdm_lock_put_irqrestore(_socket_base_lock, context);
 
-   return >sock;
+   return >sock;
+   }
 }
 
 rtdm_lock_put_irqrestore(_socket_base_lock, context);
-- 
2.7.4




Re: Towards v3.0.8

2018-11-02 Thread Sebastian Smolorz via Xenomai
Hi Jan, 

Jan Kiszka wrote:
> Hi all,
> 
> I think it would be good to release a new stable version, now that we
> have updated x86 I-pipe patches that require changes from it. I'm
> currently only aware of one open issue affecting also stable, and
> that's [1].

What is [1]?

-- 
Sebastian






Re: [PATCH 0/4] net/tcp: Fix several bugs and allow rttcp to be built

2018-11-02 Thread Sebastian Smolorz via Xenomai
Sebastian Smolorz wrote:
> On 31.10.18 19:18, Jan Kiszka wrote:
> > On 31.10.18 17:55, Pham, Phong wrote:
> > > Hi Sebastian,
> > > 
> > > The issue has to do with endianness.  We are running PowerPC (big
> > > endian).  So in rt_tcp_set_flags(), flags is 32-bit wide and *tf
> > > is
> > > 16-bit wide.  I modified the line from:
> > > 
> > > *tf = flags;
> > > 
> > > to
> > > 
> > > *tf = *(__be16 *)
> > 
> > Something is fishy with rt_tcp_set_flags. Shouldn't we rather ensure
> > that only a __be16 flag value is passed to it?
> 
> I think the reason why flags are passed as __be32 is that they are
> defined with the help of __constant_cpu_to_be32().
> 
> After reading some TCP related code in the kernel I think that this
> issue is properly fixed by
> 
> tcp_flag_word(th) = flags;
> 
> I will test this for little endian. Phong, can you test this on your
> machine?

The following patch works for me on little endian:

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index c066e06..134469c 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -280,12 +280,6 @@ static inline int rt_tcp_after(__u32 seq1, __u32 seq2)
 return (__s32)(seq2-seq1) <= 0;
 }
 
-static inline void rt_tcp_set_flags(struct tcphdr* th, __be32 flags)
-{
-__be16 *tf = ((__be16*)th) + 6;
-*tf = flags;
-}
-
 static inline u32 rt_tcp_compute_ack_seq(struct tcphdr* th, u32 len)
 {
 u32 ack_seq = ntohl(th->seq) + len;
@@ -625,11 +619,10 @@ static void rt_tcp_build_header(struct tcp_socket *ts, 
struct rtskb *skb,
 if (unlikely(is_keepalive))
th->seq--;
 
+tcp_flag_word(th) = flags;
 th->ack_seq = htonl(ts->sync.ack_seq);
 th->window  = htons(ts->sync.window);
 
-rt_tcp_set_flags(th, flags);
-
 th->doff = tcphdrlen >> 2; /* No options for now */
 th->res1 = 0;
 th->check   = 0;

-- 
Sebastian






Re: [PATCH 0/4] net/tcp: Fix several bugs and allow rttcp to be built

2018-11-02 Thread Sebastian Smolorz via Xenomai
On 31.10.18 19:18, Jan Kiszka wrote:
> On 31.10.18 17:55, Pham, Phong wrote:
> > Hi Sebastian,
> > 
> > The issue has to do with endianness.  We are running PowerPC (big
> > endian).  So in rt_tcp_set_flags(), flags is 32-bit wide and *tf is
> > 16-bit wide.  I modified the line from:
> > 
> > *tf = flags;
> > 
> > to
> > 
> > *tf = *(__be16 *)
> 
> Something is fishy with rt_tcp_set_flags. Shouldn't we rather ensure
> that only a __be16 flag value is passed to it?

I think the reason why flags are passed as __be32 is that they are defined 
with the help of __constant_cpu_to_be32().

After reading some TCP related code in the kernel I think that this 
issue is properly fixed by

tcp_flag_word(th) = flags;

I will test this for little endian. Phong, can you test this on your 
machine?

-- 
Sebastian






Re: [Xenomai] [PATCH 0/4] net/tcp: Fix several bugs and allow rttcp to be built

2018-10-31 Thread Sebastian Smolorz
Pham, Phong wrote:
> Now I encounter a different problem,
> 
> recv() returns 0 bytes but I know my FTP server sends a packet (seen
> by WireShark).  Can you point me where is the recv() implemented in
> tcp.c?  Is it rt_tcp_rcv or rt_tcp_recvmsg?

There are indeed two more issues with the rttcp driver: one in the
receive path, one in the close path. I have prepared patches for both.
Could you give them a try? I will include them in the v2 patch series
for the rttcp driver.

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index 2678e6a..3242a08 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -2084,17 +2084,10 @@ static ssize_t rt_tcp_recvmsg(struct rtdm_fd *fd, 
struct user_msghdr *msg, int m
 
len = iov[0].iov_len;
if (len > 0) {
-   buf = xnmalloc(len);
-   if (buf == NULL) {
-   ret = -ENOMEM;
-   goto out;
-   }
-   ret = rtdm_copy_from_user(fd, buf, iov[0].iov_base, len);
-   if (!ret)
-   ret = rt_tcp_read(fd, buf, len);
-   xnfree(buf);
+   buf = iov[0].iov_base;
+   ret = rt_tcp_read(fd, buf, len);
}
-out:
+
rtdm_drop_iovec(iov, iov_fast);
 
return ret;

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index 3242a08..c066e06 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -249,15 +249,18 @@ static struct rtsocket *rt_tcp_v4_lookup(u32 daddr, u16 
dport)
 {
 rtdm_lockctx_t  context;
 struct tcp_socket *ts;
+int ret;
 
 rtdm_lock_get_irqsave(_socket_base_lock, context);
 ts = port_hash_search(daddr, dport);
 
-if (ts && rt_socket_reference(>sock) == 0) {
-
-   rtdm_lock_put_irqrestore(_socket_base_lock, context);
+if (ts != NULL) {
+   ret = rt_socket_reference(>sock);
+   if (ret == 0 || (ret == -EIDRM && ts->is_closed)) {
+   rtdm_lock_put_irqrestore(_socket_base_lock, context);
 
-   return >sock;
+   return >sock;
+   }
 }
 
 rtdm_lock_put_irqrestore(_socket_base_lock, context);

-- 
Sebastian






Re: [Xenomai] [PATCH 0/4] net/tcp: Fix several bugs and allow rttcp to be built

2018-10-31 Thread Sebastian Smolorz
Pham, Phong wrote:
> This is what I see when my RTnet box, my laptop, and my FTP server
> (local on laptop) is on the same subnet 192.168.7.0:
> 
> 192.168.7.79 is my RTnet box.

Which processor architecture is it?

> I used my laptop (192.168.7.106) to
> ping the RTnet box which is what you see with ICMP protocol.  The
> first TCP packet sent by my RTnet box (packet # 11) has the SYN bit
> not set.  (see attached image.  I pulled in your patch along with the
> patch named "rtdm: add integer file descriptor to struct rtdm_fd" to
> get TCP to compile.

So you don't use latest next? Do you use stable? Did you made changes to 
the source code we are not aware of?

> Any advice you may have?  Do you know which
> relevant routine goes and set the TCP SYN bit that I can start
> looking?

It is set in rt_tcp_connect() line 1536:

ret = rt_tcp_send(ts, TCP_FLAG_SYN);

in kernel/drivers/net/stack/ipv4/tcp/tcp.c

-- 
Sebastian






Re: [Xenomai] [PATCH 0/4] net/tcp: Fix several bugs and allow rttcp to be built

2018-10-30 Thread Sebastian Smolorz
Hi,

on 10/19/18 04:00 AM, Pham, Phong wrote:
> I do see a TCP packet sent out on the LAN when rt_dev_connect() is
> invoked; however, the packet itself is not valid.  The SYN flag in
> the TCP protocol is not set when the first TCP packet was sent.

Strange. Wireshark shows me that a connection initiated by a RTnet box 
can be successfully established and that the SYN flag indeed is set.

-- 
Sebastian






[PATCH 0/3] fix several compilation and linking errors with old toolchains

2018-10-30 Thread Sebastian Smolorz
Sebastian Smolorz (3):
  lib/cobalt: Do not call glibc's {recv|send}mmsg if it is too old
  cobalt/time: add missing include for old toolchains
  utils/analogy: fix compilation of analogy_calibrate with old
toolchains

 include/cobalt/time.h | 1 +
 lib/cobalt/wrappers.c | 8 
 utils/analogy/analogy_calibrate.c | 1 -
 3 files changed, 9 insertions(+), 1 deletion(-)

-- 
2.7.4




[PATCH 2/3] cobalt/time: add missing include for old toolchains

2018-10-30 Thread Sebastian Smolorz
Without this patch compilation fails with

lib/cobalt/clock.c:251: error: conflicting types for '__wrap_clock_adjtime'
include/cobalt/time.h:43: error: previous declaration of '__wrap_clock_adjtime' 
was here
lib/cobalt/clock.c:251: error: conflicting types for '__cobalt_clock_adjtime'
include/cobalt/time.h:43: error: previous declaration of 
'__cobalt_clock_adjtime' was here

Signed-off-by: Sebastian Smolorz 
---
 include/cobalt/time.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/cobalt/time.h b/include/cobalt/time.h
index 9bafe34..6c65c77 100644
--- a/include/cobalt/time.h
+++ b/include/cobalt/time.h
@@ -23,6 +23,7 @@
 
 /* Re-read in case we came from selective __need* block. */
 #include_next 
+#include 
 #include 
 #include 
 
-- 
2.7.4




[PATCH 1/3] lib/cobalt: Do not call glibc's {recv|send}mmsg if it is too old

2018-10-30 Thread Sebastian Smolorz
Fix linking error when using glibc versions which do not provide
recvmmsg or sendmmsg.

Signed-off-by: Sebastian Smolorz 
---
 lib/cobalt/wrappers.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index 20ad63a..951cd15 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -260,7 +260,11 @@ __weak
 int __real_recvmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen,
unsigned int flags, struct timespec *timeout)
 {
+#if (__GLIBC__ == 2) && (__GLIBC_MINOR__ < 12)
+   return -ENOSYS;
+#else
return recvmmsg(fd, msgvec, vlen, flags, timeout);
+#endif
 }
 
 __weak
@@ -273,7 +277,11 @@ __weak
 int __real_sendmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen,
unsigned int flags)
 {
+#if (__GLIBC__ == 2) && (__GLIBC_MINOR__ < 14)
+   return -ENOSYS;
+#else
return sendmmsg(fd, msgvec, vlen, flags);
+#endif
 }
 
 __weak
-- 
2.7.4




[PATCH 3/3] utils/analogy: fix compilation of analogy_calibrate with old toolchains

2018-10-30 Thread Sebastian Smolorz
The previous commit introduced a fix for old toolchains by including
sys/timex.h in include/cobalt/time.h. However, that breaks the
compilation of analogy_calibrate. Removing #include 
from analogy_calibrate.c fixes compilation again.

Signed-off-by: Sebastian Smolorz 
---
 utils/analogy/analogy_calibrate.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/utils/analogy/analogy_calibrate.c 
b/utils/analogy/analogy_calibrate.c
index c5990a7..b927ee2 100644
--- a/utils/analogy/analogy_calibrate.c
+++ b/utils/analogy/analogy_calibrate.c
@@ -20,7 +20,6 @@
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-#include 
 #include 
 #include 
 #include 
-- 
2.7.4




Re: [Xenomai] [PATCH] boilerplate/avl: fix missing include

2018-10-24 Thread Sebastian Smolorz
On 10/24/18 12:47 PM, Philippe Gerum wrote:
> On 10/24/18 12:33 PM, Sebastian Smolorz wrote:
> > On 10/23/18 11:11 AM, Philippe Gerum wrote:
> >> On 10/19/18 5:10 PM, Sebastian Smolorz wrote:
> >>> Hello Philippe,
> >>> 
> >>> Sebastian Smolorz wrote:
> >>>> On 10/19/2018 09:16 AM, Philippe Gerum wrote:
> >>>>> On 10/18/2018 04:37 PM, Sebastian Smolorz wrote:
> >>>>>> Nevertheless, I guess there is an issue with the definition of
> >>>>>> const
> >>>>>> (line 50) in include/boilerplate/compiler.h. It does work with
> >>>>>> gcc
> >>>>>> 5.4 but not with gcc 4.3.5.
> >>>>> 
> >>>>> Could you elaborate on this? Which error pops us, in which
> >>>>> context?
> >>>> 
> >>>> Compilation of libboilerplate and libiniparser (master and next)
> >>>> fails with a cross gcc 4.3.5 for x86_32 (i586) targets. If I
> >>>> change the line mentioned above into
> >>>> 
> >>>> #define __const const
> >>>> 
> >>>> the error does not pop up any more. Works also when I completely
> >>>> remove the #define __const.
> >>> 
> >>> I've found two additional compile errors due to the usage of
> >>> ancient
> >>> gcc and glibc. I could prepare patches for that. But I'm not sure
> >>> how to fix this __const issue properly. I've seen that you
> >>> introduced those lines in commit  5632adb8 into -next. I suppose
> >>> you faced an issue which needed this fix, am I correct?
> >> 
> >> Adding constness to a function was needed at some point, __const
> >> was
> >> meant to be a shorthand for annotating the code. You did not
> >> provide
> >> the error message received from gcc 4.3 so I can't be sure, however
> >> the following change might fix the issue:
> >> 
> >> diff --git a/include/boilerplate/compiler.h
> >> b/include/boilerplate/compiler.h index f526eb269..469d0c249 100644
> >> --- a/include/boilerplate/compiler.h
> >> +++ b/include/boilerplate/compiler.h
> >> @@ -47,7 +47,7 @@
> >> 
> >>  #endif
> >>  
> >>  #ifndef __const
> >> 
> >> -#define __const   __attribute__((__const__))
> >> +#define __const   __attribute__((const))
> >> 
> >>  #endif
> >>  
> >>  #ifndef __pure
> > 
> > That does not change the error. The condensed error output is:
> >   CC   libboilerplate_la-ancillaries.lo
> > 
> > cc1: warnings being treated as errors
> > lib/boilerplate/iniparser/dictionary.c: In function 'xstrdup':
> > lib/boilerplate/iniparser/dictionary.c:72: error: passing argument 1
> > of 'strlen' discards qualifiers from pointer target type
> > lib/boilerplate/iniparser/dictionary.c:74: error: passing argument 2
> > of
> Ok, so this is a conflict with older libc headers defining their own
> wrappers for the const qualifier; we have no in-tree users of __pure
> and __const definitions anymore, so we should drop them, fixing the
> issue in the same move.

Thanks. Will you send out a patch for this or should I do this?

-- 
Sebastian






Re: [Xenomai] [PATCH] boilerplate/avl: fix missing include

2018-10-24 Thread Sebastian Smolorz
On 10/23/18 11:11 AM, Philippe Gerum wrote:
> On 10/19/18 5:10 PM, Sebastian Smolorz wrote:
> > Hello Philippe,
> > 
> > Sebastian Smolorz wrote:
> >> On 10/19/2018 09:16 AM, Philippe Gerum wrote:
> >>> On 10/18/2018 04:37 PM, Sebastian Smolorz wrote:
> >>>> Nevertheless, I guess there is an issue with the definition of
> >>>> const
> >>>> (line 50) in include/boilerplate/compiler.h. It does work with
> >>>> gcc
> >>>> 5.4 but not with gcc 4.3.5.
> >>> 
> >>> Could you elaborate on this? Which error pops us, in which
> >>> context?
> >> 
> >> Compilation of libboilerplate and libiniparser (master and next)
> >> fails with a cross gcc 4.3.5 for x86_32 (i586) targets. If I
> >> change the line mentioned above into
> >> 
> >> #define __const const
> >> 
> >> the error does not pop up any more. Works also when I completely
> >> remove the #define __const.
> > 
> > I've found two additional compile errors due to the usage of ancient
> > gcc and glibc. I could prepare patches for that. But I'm not sure
> > how to fix this __const issue properly. I've seen that you
> > introduced those lines in commit  5632adb8 into -next. I suppose
> > you faced an issue which needed this fix, am I correct?
> 
> Adding constness to a function was needed at some point, __const was
> meant to be a shorthand for annotating the code. You did not provide
> the error message received from gcc 4.3 so I can't be sure, however
> the following change might fix the issue:
> 
> diff --git a/include/boilerplate/compiler.h
> b/include/boilerplate/compiler.h index f526eb269..469d0c249 100644
> --- a/include/boilerplate/compiler.h
> +++ b/include/boilerplate/compiler.h
> @@ -47,7 +47,7 @@
>  #endif
> 
>  #ifndef __const
> -#define __const  __attribute__((__const__))
> +#define __const  __attribute__((const))
>  #endif
> 
>  #ifndef __pure

That does not change the error. The condensed error output is:

  CC   libboilerplate_la-ancillaries.lo
cc1: warnings being treated as errors
lib/boilerplate/iniparser/dictionary.c: In function 'xstrdup':
lib/boilerplate/iniparser/dictionary.c:72: error: passing argument 1 of 
'strlen' discards qualifiers from pointer target type
lib/boilerplate/iniparser/dictionary.c:74: error: passing argument 2 of 
'strcpy' discards qualifiers from pointer target type
lib/boilerplate/iniparser/dictionary.c: In function 'dictionary_hash':
lib/boilerplate/iniparser/dictionary.c:100: error: passing argument 1 of 
'strlen' discards qualifiers from pointer target type
lib/boilerplate/iniparser/dictionary.c: In function 'dictionary_get':
lib/boilerplate/iniparser/dictionary.c:193: error: passing argument 1 of 
'strlen' discards qualifiers from pointer target type
lib/boilerplate/iniparser/dictionary.c:193: error: 'const' attribute 
ignored
lib/boilerplate/iniparser/dictionary.c:193: error: 'const' attribute 
does not apply to types
lib/boilerplate/iniparser/dictionary.c: In function 'dictionary_set':
lib/boilerplate/iniparser/dictionary.c:242: error: passing argument 1 of 
'strlen' discards qualifiers from pointer target type
lib/boilerplate/iniparser/dictionary.c:242: error: 'const' attribute 
ignored
lib/boilerplate/iniparser/dictionary.c:242: error: 'const' attribute 
does not apply to types
lib/boilerplate/iniparser/dictionary.c: In function 'dictionary_unset':
lib/boilerplate/iniparser/dictionary.c:311: error: passing argument 1 of 
'strlen' discards qualifiers from pointer target type
lib/boilerplate/iniparser/dictionary.c:311: error: 'const' attribute 
ignored
lib/boilerplate/iniparser/dictionary.c:311: error: 'const' attribute 
does not apply to types

cc1: warnings being treated as errors
lib/boilerplate/iniparser/iniparser.c: In function 'strstrip':
lib/boilerplate/iniparser/iniparser.c:92: error: passing argument 2 of 
'strcpy' discards qualifiers from pointer target type
lib/boilerplate/iniparser/iniparser.c: In function 'iniparser_dump_ini':
lib/boilerplate/iniparser/iniparser.c:237: error: passing argument 1 of 
'strlen' discards qualifiers from pointer target type
lib/boilerplate/iniparser/iniparser.c:243: error: 'const' attribute 
ignored
lib/boilerplate/iniparser/iniparser.c:243: error: 'const' attribute does 
not apply to types
lib/boilerplate/iniparser/iniparser.c: In function 'iniparser_getint':
lib/boilerplate/iniparser/iniparser.c:314: error: passing argument 1 of 
'strtol' discards qualifiers from pointer target type
lib/boilerplate/iniparser/iniparser.c: In function 
'iniparser_getdouble':
lib/boilerplate/iniparser/iniparser.c:336: error: passing argument 1 of 
'atof' discards qualifiers from pointer target type
lib/boilerplate/iniparser/iniparser.c: In fu

Re: [Xenomai] [PATCH] boilerplate/avl: fix missing include

2018-10-19 Thread Sebastian Smolorz
Hello Philippe,

Sebastian Smolorz wrote:
> On 10/19/2018 09:16 AM, Philippe Gerum wrote:
> > On 10/18/2018 04:37 PM, Sebastian Smolorz wrote:
> > > Nevertheless, I guess there is an issue with the definition of
> > > const
> > > (line 50) in include/boilerplate/compiler.h. It does work with gcc
> > > 5.4 but not with gcc 4.3.5.
> > 
> > Could you elaborate on this? Which error pops us, in which context?
> 
> Compilation of libboilerplate and libiniparser (master and next) fails
> with a cross gcc 4.3.5 for x86_32 (i586) targets. If I change the
> line mentioned above into
> 
> #define __const const
> 
> the error does not pop up any more. Works also when I completely
> remove the #define __const.

I've found two additional compile errors due to the usage of ancient gcc 
and glibc. I could prepare patches for that. But I'm not sure how to fix 
this __const issue properly. I've seen that you introduced those lines 
in commit  5632adb8 into -next. I suppose you faced an issue which 
needed this fix, am I correct?

Thanks,

-- 
Sebastian



___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


Re: [Xenomai] [PATCH] boilerplate/avl: fix missing include

2018-10-19 Thread Sebastian Smolorz
On 10/19/2018 09:16 AM, Philippe Gerum wrote:
> On 10/18/2018 04:37 PM, Sebastian Smolorz wrote:
> > Nevertheless, I guess there is an issue with the definition of const
> > (line 50) in include/boilerplate/compiler.h. It does work with gcc
> > 5.4 but not with gcc 4.3.5.
> 
> Could you elaborate on this? Which error pops us, in which context?

Compilation of libboilerplate and libiniparser (master and next) fails 
with a cross gcc 4.3.5 for x86_32 (i586) targets. If I change the line 
mentioned above into

#define __const const

the error does not pop up any more. Works also when I completely remove 
the #define __const.

-- 
Sebastian




___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


Re: [Xenomai] [PATCH] boilerplate/avl: fix missing include

2018-10-18 Thread Sebastian Smolorz
On 18.10.18 14:37, Philippe Gerum wrote:

> On 10/18/2018 02:20 PM, Sebastian Smolorz wrote:
> > Signed-off-by: Sebastian Smolorz 
> > ---
> >  lib/boilerplate/avl.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/lib/boilerplate/avl.c b/lib/boilerplate/avl.c
> > index 3bf9bf1..2e16e7d 100644
> > --- a/lib/boilerplate/avl.c
> > +++ b/lib/boilerplate/avl.c
> > @@ -22,6 +22,7 @@
> >   */
> >  #include 
> >  #include 
> > +#include 
> >  
> >  #ifdef AVL_PSHARED
> >  #define __AVL(__decl)  shavl_ ## __decl
> > 
> 
> Nack. The proper include file needs to be included via some Makefile
> magic, depending on whether that source is build for private or shared
> mode (avl.h vs shavl.h). See Makefile.am.

Sorry for the noise, it was my fault. I was hunting another bug which
included switching gcc versions and jumping back and forth in
the git history. At some point I just forgot to execute scripts/bootstrap
and fooled myself with wrong Makefiles.

Nevertheless, I guess there is an issue with the definition of const (line 50) 
in
include/boilerplate/compiler.h. It does work with gcc 5.4 but not with
gcc 4.3.5.

-- 
Sebastian

___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] [PATCH] boilerplate/avl: fix missing include

2018-10-18 Thread Sebastian Smolorz
Signed-off-by: Sebastian Smolorz 
---
 lib/boilerplate/avl.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/boilerplate/avl.c b/lib/boilerplate/avl.c
index 3bf9bf1..2e16e7d 100644
--- a/lib/boilerplate/avl.c
+++ b/lib/boilerplate/avl.c
@@ -22,6 +22,7 @@
  */
 #include 
 #include 
+#include 
 
 #ifdef AVL_PSHARED
 #define __AVL(__decl)  shavl_ ## __decl
-- 
2.7.4


___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


Re: [Xenomai] [PATCH 0/4] net/tcp: Fix several bugs and allow rttcp to be built

2018-10-17 Thread Sebastian Smolorz
On 17.10.18 13:44, Jan Kiszka wrote:
> On 17.10.18 13:31, Sebastian Smolorz wrote:
> > This patch series makes RTnet's tcp module usable again. It was not
> > selectable in Kconfig for a long time. Now it is supposed to work in
> > the way it worked when RTnet was a separate project for Xenomai 2.
> 
> Despite the "supposed", can I assume you tested it already
> successfully with some real workload?

Tested it under QEMU with the rttcp example (rttcp-server and rttcp-
client) over rtlo. Tests on real hardware are pending and planned in the 
next few days. No problem if you want to postpone the patches until I 
report the successful outcome of those tests.

-- 
Sebastian



___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] [PATCH 2/4] net/tcp: fix listen() and shutdown() IOCTL calls

2018-10-17 Thread Sebastian Smolorz
listen() and shutdown() pass their simple int argument directly casted to
void *arg, not as a pointer to their value.

Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 12 ++--
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index c713635..8605a8c 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -1790,8 +1790,6 @@ static int rt_tcp_ioctl(struct rtdm_fd *fd,
 struct _rtdm_getsockopt_args _getopt;
 const struct _rtdm_setsockopt_args *setopt;
 struct _rtdm_setsockopt_args _setopt;
-const long *val;
-long _val;
 int in_rt;
 
 /* fast path for common socket IOCTLs */
@@ -1815,10 +1813,7 @@ static int rt_tcp_ioctl(struct rtdm_fd *fd,
return rt_tcp_connect(ts, setaddr->addr, setaddr->addrlen);
 
case _RTIOC_LISTEN:
-   val = rtnet_get_arg(fd, &_val, arg, sizeof(long));
-   if (IS_ERR(val))
-   return PTR_ERR(val);
-   return rt_tcp_listen(ts, *val);
+   return rt_tcp_listen(ts, (unsigned long)arg);
 
case _RTIOC_ACCEPT:
if (!in_rt)
@@ -1829,10 +1824,7 @@ static int rt_tcp_ioctl(struct rtdm_fd *fd,
return rt_tcp_accept(ts, getaddr->addr, getaddr->addrlen);
 
case _RTIOC_SHUTDOWN:
-   val = rtnet_get_arg(fd, &_val, arg, sizeof(long));
-   if (IS_ERR(val))
-   return PTR_ERR(val);
-   return rt_tcp_shutdown(ts, *val);
+   return rt_tcp_shutdown(ts, (unsigned long)arg);
 
case _RTIOC_SETSOCKOPT:
setopt = rtnet_get_arg(fd, &_setopt, arg, sizeof(_setopt));
-- 
2.7.4


___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] [PATCH 1/4] net/tcp: return ufd in rt_tcp_accept()

2018-10-17 Thread Sebastian Smolorz
Fix compilation error in rt_tcp_accept() when returning its socket's own file
descriptor.

Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index c5e42bc..c713635 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -1668,7 +1668,7 @@ static int rt_tcp_accept(struct tcp_socket *ts, struct 
sockaddr *addr,
 ts->is_accepted = 1;
 rtdm_lock_put_irqrestore(>socket_lock, context);
 
-ret = rt_socket_fd(>sock)->fd;
+ret = rtdm_fd_ufd(rt_socket_fd(>sock));
 
  err:
 /* it is not critical to leave this unlocked
-- 
2.7.4


___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] [PATCH 4/4] net/tcp: Allow choice of rttcp protocol in Kconfig

2018-10-17 Thread Sebastian Smolorz
Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/drivers/net/stack/ipv4/Kconfig 
b/kernel/drivers/net/stack/ipv4/Kconfig
index fef7e19..8fb3c1a 100644
--- a/kernel/drivers/net/stack/ipv4/Kconfig
+++ b/kernel/drivers/net/stack/ipv4/Kconfig
@@ -72,4 +72,4 @@ config XENO_DRIVERS_NET_RTIPV4_DEBUG
 may want to turn this on for tracing issues in packet delivery.
 
 source "drivers/xenomai/net/stack/ipv4/udp/Kconfig"
-# source "drivers/xenomai/net/stack/ipv4/tcp/Kconfig"
+source "drivers/xenomai/net/stack/ipv4/tcp/Kconfig"
-- 
2.7.4


___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] [PATCH 3/4] net/tcp: Fix bug when obtaining RST socket's private structure from its rtdm_fd pointer

2018-10-17 Thread Sebastian Smolorz
Signed-off-by: Sebastian Smolorz 
---
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index 8605a8c..2678e6a 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -182,7 +182,7 @@ static struct {
 } rst_socket_container;
 
 #define rst_fd (_socket_container.dummy.fd)
-#define rst_socket (*(struct tcp_socket *)rtdm_private_to_fd(rst_fd))
+#define rst_socket (*(struct tcp_socket *)rtdm_fd_to_private(rst_fd))
 
 static u32 tcp_auto_port_start = 1024;
 static u32 tcp_auto_port_mask  = ~(RT_TCP_SOCKETS-1);
-- 
2.7.4


___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] [PATCH 0/4] net/tcp: Fix several bugs and allow rttcp to be built

2018-10-17 Thread Sebastian Smolorz
This patch series makes RTnet's tcp module usable again. It was not
selectable in Kconfig for a long time. Now it is supposed to work in
the way it worked when RTnet was a separate project for Xenomai 2.

Sebastian Smolorz (4):
  net/tcp: return ufd in rt_tcp_accept()
  net/tcp: fix listen() and shutdown() IOCTL calls
  net/tcp: Fix bug when obtaining RST socket's private structure from
its rtdm_fd pointer
  net/tcp: Allow choice of rttcp protocol in Kconfig

 kernel/drivers/net/stack/ipv4/Kconfig   |  2 +-
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 16 
 2 files changed, 5 insertions(+), 13 deletions(-)

-- 
2.7.4


___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] [PATCH v3] rtdm: expose user-side file descriptors to drivers

2018-10-17 Thread Sebastian Smolorz
RTDM drivers refer to open files or sockets by using struct rtdm_fd.
Normally, the user-side file descriptors returned by socket() or open()
calls are not necessary for driver operations. However, in some special
cases the user-side fd has to be determined, for example as return
value of rt_tcp_accept() which is a driver function of RTnet's TCP
protocol driver.

Signed-off-by: Sebastian Smolorz 
---
 include/cobalt/kernel/rtdm/fd.h | 6 ++
 kernel/cobalt/rtdm/fd.c | 1 +
 2 files changed, 7 insertions(+)

diff --git a/include/cobalt/kernel/rtdm/fd.h b/include/cobalt/kernel/rtdm/fd.h
index 58d3c4a..572b17e 100644
--- a/include/cobalt/kernel/rtdm/fd.h
+++ b/include/cobalt/kernel/rtdm/fd.h
@@ -298,6 +298,7 @@ struct rtdm_fd {
struct rtdm_fd_ops *ops;
struct cobalt_ppd *owner;
unsigned int refs;
+   int ufd;
int minor;
int oflags;
 #ifdef CONFIG_XENO_ARCH_SYS3264
@@ -320,6 +321,11 @@ static inline struct cobalt_ppd *rtdm_fd_owner(const 
struct rtdm_fd *fd)
return fd->owner;
 }
 
+static inline int rtdm_fd_ufd(const struct rtdm_fd *fd)
+{
+   return fd->ufd;
+}
+
 static inline int rtdm_fd_minor(const struct rtdm_fd *fd)
 {
return fd->minor;
diff --git a/kernel/cobalt/rtdm/fd.c b/kernel/cobalt/rtdm/fd.c
index 8d577b2..807a11e 100644
--- a/kernel/cobalt/rtdm/fd.c
+++ b/kernel/cobalt/rtdm/fd.c
@@ -166,6 +166,7 @@ int rtdm_fd_enter(struct rtdm_fd *fd, int ufd, unsigned int 
magic,
fd->magic = magic;
fd->ops = ops;
fd->owner = ppd;
+   fd->ufd = ufd;
fd->refs = 1;
set_compat_bit(fd);
 
-- 
2.7.4


___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] [PATCH v2] rtdm: expose user-side file descriptors to drivers

2018-10-17 Thread Sebastian Smolorz
RTDM drivers refer to open files or sockets by using struct rtdm_fd.
Normally, the user-side file descriptors returned by socket() or open()
calls are not necessary for driver operations. However, in some special
cases the user-side fd has to be determined.

Signed-off-by: Sebastian Smolorz 
---
 include/cobalt/kernel/rtdm/fd.h | 6 ++
 kernel/cobalt/rtdm/fd.c | 1 +
 2 files changed, 7 insertions(+)

diff --git a/include/cobalt/kernel/rtdm/fd.h b/include/cobalt/kernel/rtdm/fd.h
index 58d3c4a..572b17e 100644
--- a/include/cobalt/kernel/rtdm/fd.h
+++ b/include/cobalt/kernel/rtdm/fd.h
@@ -298,6 +298,7 @@ struct rtdm_fd {
struct rtdm_fd_ops *ops;
struct cobalt_ppd *owner;
unsigned int refs;
+   int ufd;
int minor;
int oflags;
 #ifdef CONFIG_XENO_ARCH_SYS3264
@@ -320,6 +321,11 @@ static inline struct cobalt_ppd *rtdm_fd_owner(const 
struct rtdm_fd *fd)
return fd->owner;
 }
 
+static inline int rtdm_fd_ufd(const struct rtdm_fd *fd)
+{
+   return fd->ufd;
+}
+
 static inline int rtdm_fd_minor(const struct rtdm_fd *fd)
 {
return fd->minor;
diff --git a/kernel/cobalt/rtdm/fd.c b/kernel/cobalt/rtdm/fd.c
index 8d577b2..807a11e 100644
--- a/kernel/cobalt/rtdm/fd.c
+++ b/kernel/cobalt/rtdm/fd.c
@@ -166,6 +166,7 @@ int rtdm_fd_enter(struct rtdm_fd *fd, int ufd, unsigned int 
magic,
fd->magic = magic;
fd->ops = ops;
fd->owner = ppd;
+   fd->ufd = ufd;
fd->refs = 1;
set_compat_bit(fd);
 
-- 
2.7.4


___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] [PATCH] rtdm: add integer file descriptor to struct rtdm_fd

2018-10-16 Thread Sebastian Smolorz
RTDM drivers refer to open files or sockets by using struct rtdm_fd.
Normally, the integer file descriptor returned by socket() or open() calls
is not necessary for driver operations. However, in some special cases
this value has to be determined. To ease the retrieval of this value for
those drivers it is added directly to struct rtdm_fd. Otherwise it would
be necessary to iterate over the fd's rb_tree.

Signed-off-by: Sebastian Smolorz 
---
 include/cobalt/kernel/rtdm/fd.h | 6 ++
 kernel/cobalt/rtdm/fd.c | 1 +
 2 files changed, 7 insertions(+)

diff --git a/include/cobalt/kernel/rtdm/fd.h b/include/cobalt/kernel/rtdm/fd.h
index 58d3c4a..572b17e 100644
--- a/include/cobalt/kernel/rtdm/fd.h
+++ b/include/cobalt/kernel/rtdm/fd.h
@@ -298,6 +298,7 @@ struct rtdm_fd {
struct rtdm_fd_ops *ops;
struct cobalt_ppd *owner;
unsigned int refs;
+   int ufd;
int minor;
int oflags;
 #ifdef CONFIG_XENO_ARCH_SYS3264
@@ -320,6 +321,11 @@ static inline struct cobalt_ppd *rtdm_fd_owner(const 
struct rtdm_fd *fd)
return fd->owner;
 }
 
+static inline int rtdm_fd_ufd(const struct rtdm_fd *fd)
+{
+   return fd->ufd;
+}
+
 static inline int rtdm_fd_minor(const struct rtdm_fd *fd)
 {
return fd->minor;
diff --git a/kernel/cobalt/rtdm/fd.c b/kernel/cobalt/rtdm/fd.c
index 8d577b2..807a11e 100644
--- a/kernel/cobalt/rtdm/fd.c
+++ b/kernel/cobalt/rtdm/fd.c
@@ -166,6 +166,7 @@ int rtdm_fd_enter(struct rtdm_fd *fd, int ufd, unsigned int 
magic,
fd->magic = magic;
fd->ops = ops;
fd->owner = ppd;
+   fd->ufd = ufd;
fd->refs = 1;
set_compat_bit(fd);
 
-- 
2.7.4


___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


Re: [Xenomai] Retrieval of user fd from struct rtdm_fd

2018-10-15 Thread Sebastian Smolorz
Jan Kiszka wrote:

> On 15.10.18 15:28, Philippe Gerum wrote:
> > On 10/15/2018 03:17 PM, Sebastian Smolorz wrote:
> >> Jan Kiszka wrote:
> >>
> >>> On 14.10.18 21:27, Sebastian Smolorz wrote:
> >>>> Hello Philippe or Jan,
> >>>>
> >>>> I need to retrieve the socket file descriptor from an RTDM device driver
> >>>> routine. From what I have seen there is no simple way to obtain this int
> >>>> value from struct rtdm_fd. I have identified three possible ways to do
> >>>> this, all of them necessitate modification of Xenomai code outside the
> >>>> driver:
> >>>>
> >>>> 1. Iterate over the rb_tree rtdm_fd->owner->fds by means of the macro
> >>>> xntree_for_each_entry(pos, root, member). For this macro to work the
> >>>> definition of struct rtdm_fd_index must be known to the driver which
> >>>> means that it would have to be moved from kernel/cobalt/rtdm/fd.c to
> >>>> e.g. include/cobalt/kernel/rtdm/fd.h.
> >>>>
> >>>> 2. Similar to 1. but offer a new function rtdm_fd_get_ufd(struct rtdm_fd
> >>>> *fd) in which the rb_tree is searched.
> >>>>
> >>>> 3. Introduce a new value "int ufd" in struct rtdm_fd for setting and
> >>>> getting the ufd directly (which would be overkill I suppose because the
> >>>> vast majority of drivers don't need it).
> >>>
> >>> OTOH, that structure is not really optimized for size. So I do not see 
> >>> why it
> >>> shouldn't take yet another int, which would also be a faster API than the 
> >>> other
> >>> options.
> >>
> >> Correct. Nevertheless, we could mitigate the effect of this change by
> >> surrounding the new ufd field with
> >> #ifdef CONFIG_XENO_DRIVERS_NET_RTIPV4_TCP
> >>
> > 
> > The core layer implementing RTDM fd is not supposed to depend on high
> > level remote features such as tcp protocol over rtnet.
> > 
> > Let's just add the missing info to rtdm_fd unconditionally, we are
> > talking about a few tenths of additional bytes in a typical Xenomai
> > system fitted with several MB of memory (likely less than what would be
> > needed to scan the fd tree to retrieve the same information btw).
> > 
> 
> Ack.
> 

OK, will prepare a patch.

-- 
Sebastian



___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


Re: [Xenomai] Retrieval of user fd from struct rtdm_fd

2018-10-15 Thread Sebastian Smolorz
Jan Kiszka wrote:

> On 14.10.18 21:27, Sebastian Smolorz wrote:
> > Hello Philippe or Jan,
> > 
> > I need to retrieve the socket file descriptor from an RTDM device driver
> > routine. From what I have seen there is no simple way to obtain this int
> > value from struct rtdm_fd. I have identified three possible ways to do
> > this, all of them necessitate modification of Xenomai code outside the
> > driver:
> > 
> > 1. Iterate over the rb_tree rtdm_fd->owner->fds by means of the macro
> > xntree_for_each_entry(pos, root, member). For this macro to work the
> > definition of struct rtdm_fd_index must be known to the driver which
> > means that it would have to be moved from kernel/cobalt/rtdm/fd.c to
> > e.g. include/cobalt/kernel/rtdm/fd.h.
> > 
> > 2. Similar to 1. but offer a new function rtdm_fd_get_ufd(struct rtdm_fd
> > *fd) in which the rb_tree is searched.
> > 
> > 3. Introduce a new value "int ufd" in struct rtdm_fd for setting and
> > getting the ufd directly (which would be overkill I suppose because the
> > vast majority of drivers don't need it).
> 
> OTOH, that structure is not really optimized for size. So I do not see why it 
> shouldn't take yet another int, which would also be a faster API than the 
> other 
> options.

Correct. Nevertheless, we could mitigate the effect of this change by
surrounding the new ufd field with
#ifdef CONFIG_XENO_DRIVERS_NET_RTIPV4_TCP

-- 
Sebastian

___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


Re: [Xenomai] Retrieval of user fd from struct rtdm_fd

2018-10-15 Thread Sebastian Smolorz
Philippe Gerum wrote:

> On 10/14/2018 09:27 PM, Sebastian Smolorz wrote:
> > Hello Philippe or Jan,
> > 
> > I need to retrieve the socket file descriptor from an RTDM device driver 
> > routine.
> 
> Could you elaborate on the reason to need this?

The rttcp driver was programmed to only accept one connection
and not create a new socket for it but instead use the existing
one. So rt_tcp_accept() returns its socket's fd number.

-- 
Sebastian

___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] Retrieval of user fd from struct rtdm_fd

2018-10-14 Thread Sebastian Smolorz
Hello Philippe or Jan,

I need to retrieve the socket file descriptor from an RTDM device driver 
routine. From what I have seen there is no simple way to obtain this int 
value from struct rtdm_fd. I have identified three possible ways to do 
this, all of them necessitate modification of Xenomai code outside the 
driver:

1. Iterate over the rb_tree rtdm_fd->owner->fds by means of the macro 
xntree_for_each_entry(pos, root, member). For this macro to work the 
definition of struct rtdm_fd_index must be known to the driver which 
means that it would have to be moved from kernel/cobalt/rtdm/fd.c to 
e.g. include/cobalt/kernel/rtdm/fd.h.

2. Similar to 1. but offer a new function rtdm_fd_get_ufd(struct rtdm_fd 
*fd) in which the rb_tree is searched.

3. Introduce a new value "int ufd" in struct rtdm_fd for setting and 
getting the ufd directly (which would be overkill I suppose because the 
vast majority of drivers don't need it).

What do you think, which of the above would you prefer?

-- 
Sebastian





___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


Re: [Xenomai] Does RTNET supports TCP?

2018-10-08 Thread Sebastian Smolorz
Hi,

Pham, Phong wrote:
> Thanks and looking for your fix.  Actually the compilation is probably
> a trivial fix for you; however, since I have no familiarity of the
> code at this moment, could you provide the instruction on how to
> modify the code to make it compilable?

That will not help you much. Listening to a socket also fails. And if I 
would provide you also with a quick fix for that bug a null pointer 
exception will hit you when your application calls connect(). So please 
have a little more patience. Fixing all of those bugs together in a 
patch set  makes a lot of sense.

> I am still in the early
> process of establishing a connection so I can work out any further
> issues while waiting for your official fix (which includes several
> other bugs)?  Thanks.

 
> Hi Steven,
> 
> You wrote:
> 
> > Try SOCK_DGRAM and see if it
> > works. If not, then are you sure you have rtnet drivers for your
> > network device compiled and ready to use? Remember, the driver for
> > your network device must be realtime-safe.
> 
> 
> My current network device driver is actually working because it is the
> one provided/ported by Xenomai (even though I did have to modify the
> buffer size on one of the buffers).  In fact, I am able to ping to
> successfully (but ping uses ICMP).  I need TCP because our current
> application (VxWorks based) accesses a FTP server to retrieve files
> and I would like to maintain that resemblance in Linux.  What I don't
> need is the real-time functionality.

Hm ... then why don't you fetch your files in non-realtime context? This 
would be much easier I suppose.

-- 
Sebastian




___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


Re: [Xenomai] Does RTNET supports TCP?

2018-10-06 Thread Sebastian Smolorz
Hi all,

Steven Seeger wrote:
> On Thursday, October 4, 2018 9:02:46 PM EDT Pham, Phong wrote:
> > Hi,
> > 
> > I noticed starting Xenomai 3.0.1 until now (3.0.7), there is net/ in
> > .../kernel/drivers/ and in ../kernel/drivers/net/stack/ipv4/Kconfig
> > 
> > # source "drivers/xenomai/net/stack/ipv4/tcp/Kconfig"
> 
> I don't know why this is commented out. It looks like Gilles's initial
> import of this file in commit
> 106ffba7b55d506143966ff16158ee79b0007336 had it commented out.
> 
> I know that UDP is typically used with RTNET. TCP is complicated and
> has a lot of timers and dynamic state that makes it less than
> desirable for hard- realtime systems. Probably Jan should chime in on
> this. I think he has the most experience using RTnet at this point.
> 
> > 5)  When I created a socket with rt_dev_socket(AF_INET,
> > SOCK_STREAM, 0); and attempting to rt_dev_connect(fd,
> > server_ip_addr,
> > sizeof(server_ip_addr)), I get errno = 25 (Inappropriate ioctl for
> > device).> 
> >  Does it mean b/c TCP is not supported in RTnet and I attempt to
> >  connect> 
> > via TCP (w/ socket SOCK_STREAM)?
> 
> Sorry I can't answer the other questions, as I am not working on rtnet
> myself. However, I would suspect that since TCP doesn't compile that
> is why SOCK_STREAM is not working.

In the old days of Xenomai 2.6 rttcp worked so I am confident that we can 
make it work again.

Currently, I am working on fixing two additional bugs in rttcp and I can 
include this compile bug in rt_tcp_accept() Phong found. I will soon 
come up with a patch series, I think.

> Try SOCK_DGRAM and see if it
> works. If not, then are you sure you have rtnet drivers for your
> network device compiled and ready to use? Remember, the driver for
> your network device must be realtime-safe. I recall seeing a guide
> for some simple changes to make to a Linux ethernet driver to use as
> a starting point for porting it to RTNET, but I can't seem to find
> it. Anyone?

Do you mean kernel/drivers/net/doc/README.drvporting?

-- 
Sebastian





___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] [PATCH] drivers/can: Add PCAN-PCI Express OEM ID.

2018-08-29 Thread Sebastian Smolorz
---
 kernel/drivers/can/sja1000/rtcan_peak_pci.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/drivers/can/sja1000/rtcan_peak_pci.c 
b/kernel/drivers/can/sja1000/rtcan_peak_pci.c
index 3da1657..0fdc598 100644
--- a/kernel/drivers/can/sja1000/rtcan_peak_pci.c
+++ b/kernel/drivers/can/sja1000/rtcan_peak_pci.c
@@ -78,6 +78,7 @@ struct rtcan_peak_pci
 #define PEAK_PC_104P_DEVICE_ID  0x0006  // PCAN-PC/104+ cards
 #define PEAK_PCI_104E_DEVICE_ID 0x0007  // PCAN-PCI/104 Express cards
 #define PEAK_MPCIE_DEVICE_ID0x0008  // The miniPCIe slot cards
+#define PEAK_PCIE_OEM_ID0x0009  // PCAN-PCI Express OEM
 
 #define PCI_CONFIG_PORT_SIZE 0x1000  // size of the config io-memory
 #define PCI_PORT_SIZE0x0400  // size of a channel io-memory
@@ -90,6 +91,7 @@ static struct pci_device_id peak_pci_tbl[] = {
{PEAK_PCI_VENDOR_ID, PEAK_PC_104P_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
{PEAK_PCI_VENDOR_ID, PEAK_PCI_104E_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
{PEAK_PCI_VENDOR_ID, PEAK_CPCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
+   {PEAK_PCI_VENDOR_ID, PEAK_PCIE_OEM_ID, PCI_ANY_ID, PCI_ANY_ID,},
{ }
 };
 MODULE_DEVICE_TABLE (pci, peak_pci_tbl);
-- 
2.7.4


___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] [PATCH v2] net: Split internal rtnet.h and install rtdm/net.h and rtdm/uapi/net.h

2018-08-16 Thread Sebastian Smolorz
For external projects wanting to use RTnet with its special
features like RTnet IOCTLs it is necessary to provide the API
headers in the Xenomai installation directory.
---
 include/cobalt/kernel/rtdm/net.h|  45 +
 include/rtdm/Makefile.am|   1 +
 include/rtdm/net.h  |  38 
 include/rtdm/uapi/Makefile.am   |   1 +
 include/rtdm/uapi/net.h |  75 +++
 kernel/drivers/net/drivers/at91_ether.c |   2 +-
 kernel/drivers/net/drivers/macb.c   |   2 +-
 kernel/drivers/net/stack/include/rtmac.h|   2 -
 kernel/drivers/net/stack/include/rtnet.h| 121 
 kernel/drivers/net/stack/include/rtnet_socket.h |   4 +-
 kernel/drivers/net/stack/include/rtskb.h|   2 +-
 kernel/drivers/net/stack/ipv4/tcp/timerwheel.h  |   2 +-
 kernel/drivers/net/stack/rtdev_mgr.c|   2 +-
 kernel/drivers/net/stack/socket.c   |   2 +-
 14 files changed, 167 insertions(+), 132 deletions(-)
 create mode 100644 include/cobalt/kernel/rtdm/net.h
 create mode 100644 include/rtdm/net.h
 create mode 100644 include/rtdm/uapi/net.h
 delete mode 100644 kernel/drivers/net/stack/include/rtnet.h

diff --git a/include/cobalt/kernel/rtdm/net.h b/include/cobalt/kernel/rtdm/net.h
new file mode 100644
index 000..07198f8
--- /dev/null
+++ b/include/cobalt/kernel/rtdm/net.h
@@ -0,0 +1,45 @@
+/*
+ *  RTnet - real-time networking subsystem
+ *  Copyright (C) 2005-2011 Jan Kiszka 
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _COBALT_RTDM_NET_H
+#define _COBALT_RTDM_NET_H
+
+#include 
+#include 
+#include 
+
+struct rtnet_callback {
+void(*func)(struct rtdm_fd *, void *);
+void*arg;
+};
+
+#define RTNET_RTIOC_CALLBACK_IOW(RTIOC_TYPE_NETWORK, 0x12, \
+struct rtnet_callback)
+
+/* utility functions */
+
+/* provided by rt_ipv4 */
+unsigned long rt_inet_aton(const char *ip);
+
+/* provided by rt_packet */
+int rt_eth_aton(unsigned char *addr_buf, const char *mac);
+
+#define RTNET_RTDM_VER 914
+
+#endif  /* _COBALT_RTDM_NET_H */
diff --git a/include/rtdm/Makefile.am b/include/rtdm/Makefile.am
index 9198595..828bf73 100644
--- a/include/rtdm/Makefile.am
+++ b/include/rtdm/Makefile.am
@@ -9,6 +9,7 @@ includesub_HEADERS +=   \
can.h   \
gpio.h  \
ipc.h   \
+   net.h   \
serial.h\
spi.h   \
testing.h   \
diff --git a/include/rtdm/net.h b/include/rtdm/net.h
new file mode 100644
index 000..1a667bd
--- /dev/null
+++ b/include/rtdm/net.h
@@ -0,0 +1,38 @@
+/***
+ *
+ *  rtdm/net.h
+ *
+ *  RTnet - real-time networking subsystem
+ *  Copyright (C) 2005-2011 Jan Kiszka 
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *  As a special exception to the GNU General Public license, the RTnet
+ *  project allows you to use this header file in unmodified form to produce
+ *  application programs executing in user-space which use RTnet services by
+ *  normal system calls. The resulting executable will not be covered by the
+ *  GNU General Public License merely as a result of this header file use.
+ *  Instead, this header file use will be considered normal use of RTnet and
+ *  not a "derived work" in the sense of the GNU General Public License.
+ *
+ */
+
+#ifndef _RTDM_NET_H
+#define _RTDM_NET_H
+
+#include 
+#include 
+
+#endif  /* !_RTDM_NET_H */
diff --git a/include/rtdm/uapi/Makefile.am b/include/rtdm/uapi/Makefile.am
index fec15db..c962552 100644

Re: [Xenomai] [PATCH] net: Split internal rtnet.h into rtdm/net.h and rtdm/uapi/net.h and install them

2018-08-16 Thread Sebastian Smolorz
On 08/16/2018, 11:03:18 CEST Philippe Gerum wrote:
> On 08/16/2018 10:44 AM, Sebastian Smolorz wrote:
> > On 08/15/2018, 16:16:09 CEST Philippe Gerum wrote:
> >> On 08/14/2018 09:07 AM, Sebastian Smolorz wrote:
> >>> For external projects wanting to use RTnet with its special
> >>> features like RTnet IOCTLs it is necessary to provide the API
> >>> headers in the Xenomai installation directory.
> >> 
> >> Assuming there is no ABI change, and net/stack/include/rtnet.h was
> >> not part of any external API, do you push this for inclusion in
> >> the -stable branch too?
> > 
> > My assumption was that Xenomai API headers which are supposed to be
> > used by external projects are installed into the installation
> > directory. All other headers are internal to the Xenomai project
> > and using them for external project would be kind of a misuse. With
> > this assumption in mind I found out that rtnet.h was no part of the
> > API in the installation directory. Thinking this further the patch
> > could be very suitable for the stable branch because it adds the
> > RTnet API where Xenomai 3 lacked it so far (at least inside the
> > installation directory).
> 
> Ack.
> 
> > But I have got some doubts about my patch at a different point: I
> > thought that rtdm/net.h would be for inclusion by RTnet drivers and
> > rtdm/uapi/net.h for userland. Looking at the other RTDM headers this
> > seems not to be true. The API for kernel drivers is located only in
> > include/cobalt/kernel/rtdm/, isn't it? I think I have to prepare a
> > PATCH v2.
> 
> The current layout for RTDM-based features is as follows:
> 
> kernel API header: include/cobalt/kernel/rtdm/
> user API header: include/rtdm/
> shared API bits between user and kernel: include/rtdm/uapi/

Thanks for the clarification. I will send out a PATCH v2 shortly.

-- 
Sebastian



___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


Re: [Xenomai] [PATCH] net: Split internal rtnet.h into rtdm/net.h and rtdm/uapi/net.h and install them

2018-08-16 Thread Sebastian Smolorz
On 08/15/2018, 16:16:09 CEST Philippe Gerum wrote:
> On 08/14/2018 09:07 AM, Sebastian Smolorz wrote:
> > For external projects wanting to use RTnet with its special
> > features like RTnet IOCTLs it is necessary to provide the API
> > headers in the Xenomai installation directory.
> 
> Assuming there is no ABI change, and net/stack/include/rtnet.h was not
> part of any external API, do you push this for inclusion in the
> -stable branch too?

My assumption was that Xenomai API headers which are supposed to be used 
by external projects are installed into the installation directory. All 
other headers are internal to the Xenomai project and using them for 
external project would be kind of a misuse. With this assumption in mind 
I found out that rtnet.h was no part of the API in the installation 
directory. Thinking this further the patch could be very suitable for 
the stable branch because it adds the RTnet API where Xenomai 3 lacked 
it so far (at least inside the installation directory).

But I have got some doubts about my patch at a different point: I 
thought that rtdm/net.h would be for inclusion by RTnet drivers and 
rtdm/uapi/net.h for userland. Looking at the other RTDM headers this 
seems not to be true. The API for kernel drivers is located only in 
include/cobalt/kernel/rtdm/, isn't it? I think I have to prepare a PATCH 
v2.

-- 
Sebastian



___
Xenomai mailing list
Xenomai@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai


[Xenomai] [PATCH] net: Split internal rtnet.h into rtdm/net.h and rtdm/uapi/net.h and install them

2018-08-14 Thread Sebastian Smolorz
For external projects wanting to use RTnet with its special
features like RTnet IOCTLs it is necessary to provide the API
headers in the Xenomai installation directory.
---
 include/cobalt/kernel/rtdm/net.h|  47 +
 include/rtdm/Makefile.am|   1 +
 include/rtdm/net.h  |  46 +
 include/rtdm/uapi/Makefile.am   |   1 +
 include/rtdm/uapi/net.h |  73 ++
 kernel/drivers/net/drivers/at91_ether.c |   2 +-
 kernel/drivers/net/drivers/macb.c   |   2 +-
 kernel/drivers/net/stack/include/rtmac.h|   2 -
 kernel/drivers/net/stack/include/rtnet.h| 121 
 kernel/drivers/net/stack/include/rtnet_socket.h |   4 +-
 kernel/drivers/net/stack/include/rtskb.h|   2 +-
 kernel/drivers/net/stack/ipv4/tcp/timerwheel.h  |   2 +-
 kernel/drivers/net/stack/rtdev_mgr.c|   2 +-
 kernel/drivers/net/stack/socket.c   |   2 +-
 14 files changed, 175 insertions(+), 132 deletions(-)
 create mode 100644 include/cobalt/kernel/rtdm/net.h
 create mode 100644 include/rtdm/net.h
 create mode 100644 include/rtdm/uapi/net.h
 delete mode 100644 kernel/drivers/net/stack/include/rtnet.h

diff --git a/include/cobalt/kernel/rtdm/net.h b/include/cobalt/kernel/rtdm/net.h
new file mode 100644
index 000..1f8eb78
--- /dev/null
+++ b/include/cobalt/kernel/rtdm/net.h
@@ -0,0 +1,47 @@
+/*
+ *  cobalt/kernel/rtdm/net.h
+ *
+ *  RTnet - real-time networking subsystem
+ *  Copyright (C) 2005-2011 Jan Kiszka 
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _COBALT_RTDM_NET_H
+#define _COBALT_RTDM_NET_H
+
+#include 
+#include 
+#include 
+
+struct rtnet_callback {
+void(*func)(struct rtdm_fd *, void *);
+void*arg;
+};
+
+#define RTNET_RTIOC_CALLBACK_IOW(RTIOC_TYPE_NETWORK, 0x12, \
+struct rtnet_callback)
+
+/* utility functions */
+
+/* provided by rt_ipv4 */
+unsigned long rt_inet_aton(const char *ip);
+
+/* provided by rt_packet */
+int rt_eth_aton(unsigned char *addr_buf, const char *mac);
+
+#define RTNET_RTDM_VER 914
+
+#endif  /* _COBALT_RTDM_NET_H */
diff --git a/include/rtdm/Makefile.am b/include/rtdm/Makefile.am
index 9198595..828bf73 100644
--- a/include/rtdm/Makefile.am
+++ b/include/rtdm/Makefile.am
@@ -9,6 +9,7 @@ includesub_HEADERS +=   \
can.h   \
gpio.h  \
ipc.h   \
+   net.h   \
serial.h\
spi.h   \
testing.h   \
diff --git a/include/rtdm/net.h b/include/rtdm/net.h
new file mode 100644
index 000..7f0ed40
--- /dev/null
+++ b/include/rtdm/net.h
@@ -0,0 +1,46 @@
+/***
+ *
+ *  rtdm/net.h
+ *
+ *  RTnet - real-time networking subsystem
+ *  Copyright (C) 2005-2011 Jan Kiszka 
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _RTDM_NET_H
+#define _RTDM_NET_H
+
+#include 
+#include 
+#include 
+
+struct rtnet_callback {
+void(*func)(struct rtdm_fd *, void *);
+void*arg;
+};
+
+#define RTNET_RTIOC_CALLBACK_IOW(RTIOC_TYPE_NETWORK, 0x12, \
+struct rtnet_callback)
+
+/* utility functions */
+
+/* provided by rt_ipv4 */
+unsigned long rt_inet_aton(const char *ip);
+
+/* provided by rt_packet */
+int rt_eth_aton(unsigned char *addr_buf, const char *mac);
+
+#endif  /* _RTDM_NET_H */
diff --git a/include/rtdm/uapi/Makefile.am b/include/rtdm/uapi/Makefile.am
index fec15db..c962552 100644
--- a/include/rtdm/uapi/Makefile.am
+++ b/include/rtdm/uapi/Makefile.am
@@ -9,6