create cor_dev
[cor.git] / net / cor / cor.h
blob686eee6ad3307d15a2955c276fd0445f782f24cc
1 /**
2 * Connection oriented routing
3 * Copyright (C) 2007-2021 Michael Blizek
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/atomic.h>
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/interrupt.h>
21 #include <linux/sched.h>
22 #include <linux/netdevice.h>
23 #include <linux/skbuff.h>
24 #include <linux/spinlock.h>
25 #include <linux/workqueue.h>
26 #include <linux/kref.h>
27 #include <linux/ktime.h>
28 #include <linux/rbtree.h>
30 #include <linux/socket.h>
31 #include <net/sock.h>
33 #include <linux/math64.h>
35 #include "settings.h"
38 #define ETH_P_COR 0x1022
39 #define AF_COR 99
40 #define PF_COR AF_COR
42 #define PROTO_COR_RAW 0
43 #define PROTO_COR_RDEAMON 1
45 struct cor_sockaddr {
46 __u16 sin_family;
48 __be32 port;
49 __be64 addr;
52 #define COR_PASS_ON_CLOSE 1
54 #define COR_PUBLISH_SERVICE 2
56 #define COR_TOS 3
57 #define COR_TOS_DEFAULT 0
58 #define COR_TOS_LOW_LATENCY 1
59 #define COR_TOS_HIGH_LATENCY 2
61 #define COR_PRIORITY 4
63 #define MAX_CONN_CMD_LEN 64
65 #define PACKET_TYPE_NONE 0
66 #define PACKET_TYPE_ANNOUNCE 1
67 #define PACKET_TYPE_CMSG_NOACK 2
68 #define PACKET_TYPE_CMSG_ACKSLOW 3
69 #define PACKET_TYPE_CMSG_ACKFAST 4
70 #define PACKET_TYPE_CONNDATA 64
72 #define PACKET_TYPE_CONNDATA_FLAGS 63
73 #define PACKET_TYPE_CONNDATA_FLAGS_FLUSH 32
74 #define PACKET_TYPE_CONNDATA_FLAGS_WINDOWUSED 31
77 /**
78 * Announce data format:
79 * version [2]
80 * is 0, may be increased if the protocol changes
81 * min_version [2]
82 * is 0, must be increased if a future version of the protocol is incompatible
83 * to the current version
84 * [data]
86 * Data format of the announce packet "data" field:
87 *{command [2] commandlength [2] commanddata [commandlength]}[...]
90 /* Commands */
92 /* ANNCMD_VERSION: version[2] minversion[2] */
93 #define ANNCMD_VERSION 1
95 /* ANNCMD_ADDR: addr[8] */
96 #define ANNCMD_ADDR 2
98 /* ANNCMD_NOADDR: (no params) */
99 #define ANNCMD_NOADDR 3
103 * Kernel packet data - these commands are sent by the neighbor
104 * The end nodes may cause these commands to be sent, but they see them beyond
105 * the first hop.
107 #define KP_MISC 0
108 #define KP_ACK_CONN 1
109 #define KP_CONN_DATA 2
111 /* KP_PADDING[1] */
112 #define KP_MISC_PADDING 0
115 * KP_INIT_SESSION[1] sessionid[4]
117 * finishes neighbor discovery and starts a session
119 * Before this is received all other commands are ignored. The sessionid is used
120 * to prevent usage of old neighbor discovery data (e.g. addresses)
122 #define KP_MISC_INIT_SESSION 1
124 #define KP_MISC_INIT_SESSION_CMDLEN 5
127 * KP_PING[1] cookie[4]
128 * KP_PONG[1] cookie[4] respdelay_full[4] respdelay_netonly[4]
130 * This is needed to find out whether the other node is reachable. After a new
131 * neighbor is seen, ping requests are sent and the neighbor is only reachable
132 * after a few pongs are received. These requests are also used to find out
133 * whether a neighber is gone.
135 * respdelay:
136 * The receiver of a ping may delay the sending of the pong e.g. to create
137 * bigger packets. The respdelay is the time in microseconds the packet was
138 * delayed.
140 #define KP_MISC_PING 2
142 #define KP_MISC_PING_CMDLEN 5
144 #define KP_MISC_PONG 3
146 /* KP_ACK[1] seqno[4] */
147 #define KP_MISC_ACK 4
150 * NOTE on connection ids:
151 * connection ids we receive with most significant bit 0 have been generated by
152 * us
153 * connection ids we receive with most significant bit 1 have been generated by
154 * the other side
156 * ATTENTION: the priority seqno are reversed:
157 * priority seqnos we send are used when we send updates
158 * priority seqnos we received are used when we receive updates
162 * incoming connection
163 * seqno1... used to ack data sent from the side which initiated the connection
164 * seqno2... used to ack data sent to the side which initiated the connection
165 * KP_CONNECT[1] conn_id[4] seqno1[4] seqno2[4] window[1] priority_seqno[0.5]
166 * priority[1.5] is_highlatency[1]
168 #define KP_MISC_CONNECT 5
171 * incoming connection successful,
172 * KP_CONNECT_SUCCESS[1] conn_id[4] window[1]
174 #define KP_MISC_CONNECT_SUCCESS 6
177 * KP_RESET_CONN[1] conn_id[4]
178 * We send this, if there is an established connection we want to close.
180 #define KP_MISC_RESET_CONN 7
183 * KP_SET_MAX_CMSG_DELAY[1] cpacket_ack_fast_delay[4] cpacket_ack_slow_delay[4]
184 * data_ack_delay[4] cmsg_delay[4]
185 * Sent after connecting and at any change
186 * delay in specifies in microsecs
188 #define KP_MISC_SET_MAX_CMSG_DELAY 8
190 #define KP_MISC_SET_MAX_CMSG_DELAY_CMDLEN 17
193 * KP_MISC_SET_RECEIVE_MTU[1] receive_mtu[4]
194 * Sent after connecting and at any change
196 #define KP_MISC_SET_RECEIVE_MTU 9
198 #define KP_MISC_SET_RECEIVE_MTU_CMDLEN 5
202 * KP_ACK_CONN[1] conn_id[4] delay_remaining[1] seqno[4] window[2]
203 * bufsize_changerate[1] seqno_ooo[4]
204 * length[1-4] priority_seqno[0.5] priority[1.5] is_highlatency[1]
206 * conn_id is the conn_id we use if we sent something through this conn and
207 * *not* the conn_id that the neighbor used to send us the data
209 * delay_remaining = time the ack_conn could have remained in the queue
210 * 255 means the ack_conn has been sent immediately
211 * 0 means it has been delayed by as much the delay set by SET_MAX_CMSG_DELAY
213 * seqno = the seqno which is expected in the next non-out-of-order packet
215 * window = amount of data which can be sent without receiving the next ack
216 * packets with lower seqno do not overwrite the last window size
217 * The window may also be reduced. However, this only indicates a wish.
218 * Packets must be accepted if they exceed the new window, but not the old
219 * one.
221 * decode:
222 * 0 = 0
223 * 1...255 = 64*2^((value-1)/7) end result is rounded down to an integer
225 * bufsize_changerate = if the next router(s) is increasing or decreasing its
226 * buffer size
227 * 0 = for every byte we can send, the end host will receive 2 bytes
228 * 64 = for every byte we can send, the end host will receive 1 byte
229 * 128 = for every 2 byte we can send, the end host will receive 1 byte
230 * ...
232 * seqno_ooo, length = This packet was received out of order. Maybe a previous
233 * packet has been lost. Out of order data should not be retransmitted.
234 * Multiple ooo packets may be merged into a single ack. Ooo packets may be
235 * partially accepted, so that the length does not cover the full packet and/
236 * or the seqno starts in the middle of a packet
238 #define KP_ACK_CONN_FLAGS_SEQNO 1
239 #define KP_ACK_CONN_FLAGS_WINDOW 2
240 #define KP_ACK_CONN_FLAGS_OOO 12 /* 4+8 */
241 #define KP_ACK_CONN_FLAGS_PRIORITY 16
243 static inline __u8 cor_ooolen_to_flags(__u32 len)
245 if (len == 0)
246 return 0;
247 if (len < 256)
248 return 4;
249 if (len < 65536)
250 return 8;
251 return 12;
254 static inline int cor_ooolen(__u8 flags)
256 int len = ((flags & KP_ACK_CONN_FLAGS_OOO) >> 2);
258 if (unlikely(len == 3))
259 return 4;
260 return len;
263 static inline int cor_ack_conn_len(__u8 flags)
265 int len = 0;
267 if ((flags & KP_ACK_CONN_FLAGS_SEQNO) != 0) {
268 len += 4;
269 if ((flags & KP_ACK_CONN_FLAGS_WINDOW) != 0)
270 len += 2;
273 if (cor_ooolen(flags) != 0) {
274 len += 4;
275 len += cor_ooolen(flags);
278 /* delay_remaining */
279 if ((flags & KP_ACK_CONN_FLAGS_SEQNO) != 0 ||
280 cor_ooolen(flags) != 0)
281 len++;
283 if (flags & KP_ACK_CONN_FLAGS_PRIORITY)
284 len += 3;
286 return len;
289 /* KP_CONN_DATA[1] conn_id[4] seqno[4] length[1-2] data[length] */
290 #define KP_CONN_DATA_FLAGS_WINDOWUSED 31
291 #define KP_CONN_DATA_FLAGS_FLUSH 32
293 #define KP_CONN_DATA_MAXLEN (128 + 32767)
295 static inline __u32 get_kp_conn_data_length(__u32 datalen)
297 if (datalen < 128)
298 return 10 + datalen;
299 else
300 return 11 + datalen;
303 static inline __u8 get_kp_code(__u8 maj, __u8 min)
305 BUILD_BUG_ON(maj > 3);
306 BUG_ON(min > 63);
307 return (maj << 6) + min;
310 static inline __u8 kp_maj(__u8 code)
312 return code >> 6;
315 static inline __u8 kp_min(__u8 code)
317 return code & 63;
322 * Connection data which in interpreted when connection has no target yet
323 * These commands are sent by the end node.
325 * Format:
326 * cmd[2] length[1-4] parameter[length]
327 * unrecogniced commands are ignored
328 * parameters which are longer than expected are ignored as well
331 #define CD_CONTINUE_ON_ERROR_FLAG 32768
332 #define CD_NOPARAM_FLAG 16384
334 /* outgoing connection: CD_CONNECT_NB[2] length[1-4] addr[8] */
335 #define CD_CONNECT_NB 1
337 /* connection to local open part: CD_CONNECT_PORT[2] length[1-4] port[4] */
338 #define CD_CONNECT_PORT 2
341 * list connected neighbors: CD_LIST_NEIGH[2] length[1-4]
342 * responds with CDR_BINDATA if successful
343 * The response
344 * format is:
346 * numneighs[1-4]
347 * numfields[1-4] (field[2] fieldlen[1-4])[numfields]
348 * rows[responserows]:
349 * fieldlen[1-4], only if fieldlen in the header was "0"
350 * fielddata[fieldlen]
352 * Future versions may append data to field definition. Clients must silently
353 * discard fields they do not expect.
355 #define CD_LIST_NEIGH 3
358 * addr[fieldlen]
360 #define LIST_NEIGH_FIELD_ADDR 1
363 * latency_in_microsecs[1] (64_11 encoding)
364 * Only raw network latency in measured. Delays caused by the priority queues
365 * are *not* included.
367 #define LIST_NEIGH_FIELD_LATENCY 2
370 * list services: CD_LIST_SERVICES[2] length[1-4]
371 * responds with CDR_BINDATA if successful
373 #define CD_LIST_SERVICES 4
376 * list services: CD_LIST_SERVICES[2] length[1-4]
377 * responds with CDR_BINDATA if successful
379 #define CD_LIST_L4PROTOCOLS 5
383 * Connection data response
384 * Format is the same as with connection data
388 * CDR_EXECOK[1]
390 #define CDR_EXECOK 1
393 * CDR_EXEOK_BINDATA[1] bindatalen[1-4] bindata[bindatalen]
394 * CDR_EXECOK_BINDATA_NORESP[1]
396 #define CDR_EXECOK_BINDATA 2
397 #define CDR_EXECOK_BINDATA_NORESP 3
400 * CDR_EXECFAILED[1] reasoncode[2]
402 #define CDR_EXECFAILED 4
403 #define CDR_EXECFAILED_INVALID_COMMAND 1
404 #define CDR_EXECFAILED_COMMAND_PARSE_ERROR 2
405 #define CDR_EXECFAILED_TEMPORARILY_OUT_OF_RESOURCES 3
406 #define CDR_EXECFAILED_NB_DOESNTEXIST 4
407 #define CDR_EXECFAILED_UNKNOWN_L4PROTOCOL 5
408 #define CDR_EXECFAILED_PORTCLOSED 6
410 #define L4PROTO_STREAM 42399
414 * routing daemon sock
415 * format:
416 * cmdcode[4] length[4] cmddata[length]
418 #define CRD_KTU_SUPPORTEDVERSIONS 1
420 * CRD_KTU_SUPPORTEDVERSIONS[4] length[4] min[4] max[4]
423 #define CRD_KTU_CONNECT 2
425 * CRD_KTU_KTOU_CONNECT[4] length[4] cookie[8] targetlen[4] target[targetlen]
428 #define CRD_UTK_VERSION 1
430 * CRD_UTK_VERSION[4] length[4] version[4]
433 #define CRD_UTK_UP 2
434 #define CRD_UTK_UP_FLAGS_ADDR 1
435 #define CRD_UTK_UP_FLAGS_INTERFACES 2
437 * CRD_UTK_UP[4] length[4] flags[8]
438 * if CRD_UTK_UP_FLAGS_ADDR
439 * addr[8]
440 * if CRD_UTK_UP_FLAGS_INTERFACES:
441 * num_interfaces[4] (length[4] interface[length])[num_interfaces]
445 #define CRD_UTK_CONNECTERROR 3
447 * CRD_UTK_CONNECTERROR[4] length[4] cookie[8] error[4]
450 #define CRD_UTK_CONNECTERROR_ACCES 1
451 #define CRD_UTK_CONNECTERROR_NETUNREACH 2
452 #define CRD_UTK_CONNECTERROR_TIMEDOUT 3
453 #define CRD_UTK_CONNECTERROR_REFUSED 4
455 #define CONN_MNGD_HEADERLEN 2
456 #define CONN_MNGD_MAX_CTRL_DATALEN 8
457 #define CONN_MNGD_CHECKSUMLEN 4
459 #define CONN_MNGD_HASDATA (1 << 15)
460 #define CONN_MNGD_EOF (1 << 0)
461 #define CONN_MNGD_RCVEND (1 << 1)
462 #define CONN_MNGD_KEEPALIVE_REQ (1 << 2)
463 #define CONN_MNGD_KEEPALIVE_RESP (1 << 3)
464 #define CONN_MNGD_DATALEN 4095
466 #define CONN_MNGD_MAX_SEGMENT_SIZE (CONN_MNGD_DATALEN + 1)
469 struct cor_interface_config {
470 char *name;
471 __u32 name_len;
474 #define CONGSTATUS_NONE 0
475 #define CONGSTATUS_CONNDATA 1
476 #define CONGSTATUS_ANNOUNCE 2
477 #define CONGSTATUS_RETRANS 3
478 #define CONGSTATUS_KPACKETS 4
480 struct cor_dev {
481 struct list_head dev_list;
483 struct net_device *dev; /* may not change while queue is in list */
485 struct {
486 spinlock_t qlock;
488 __u8 is_destroyed;
490 struct task_struct *qos_resume_thread;
491 wait_queue_head_t qos_resume_wq;
492 atomic_t qos_resume_scheduled;
493 unsigned long jiffies_lastprogress;
495 struct list_head kpackets_waiting;
496 struct list_head conn_retrans_waiting;
497 struct list_head announce_waiting;
498 struct list_head neighbors_waiting;
499 struct list_head neighbors_waiting_nextpass;
501 unsigned long jiffies_nb_pass_start;
502 unsigned long jiffies_nb_lastduration;
505 unsigned long jiffies_lastdrop;
507 __u32 numconns;
508 __u64 priority_sum;
510 atomic_t cong_status;
511 }send_queue;
513 struct kref ref;
518 * switch to and from RB_INQUEUE_NBCONGWIN is only done with nbcongwin.lock
519 * *and* qlock held
521 #define RB_INQUEUE_FALSE 0
522 #define RB_INQUEUE_TRUE 1
523 #define RB_INQUEUE_NBCONGWIN 2 /* only for nb->rb */
524 #define RB_INQUEUE_NBNOTACTIVE 3 /* only for nb->rb */
526 struct cor_resume_block {
527 struct list_head lh;
528 __u8 in_queue;
531 #define ANNOUNCE_TYPE_BROADCAST 1
532 #define ANNOUNCE_TYPE_UNICAST 2
534 struct cor_announce_data {
535 struct kref ref;
537 struct list_head lh;
538 __u8 type;
539 __u16 sndcnt;
540 struct net_device *dev;
541 char mac[MAX_ADDR_LEN];
542 struct delayed_work announce_work;
543 struct cor_resume_block rb;
546 struct cor_neighbor_discdata {
547 struct list_head lh;
548 unsigned long jiffies_created;
550 __be32 sessionid;
552 struct net_device *dev;
553 char mac[MAX_ADDR_LEN];
555 __u8 nb_allocated;
557 __u8 rcvd_version;
558 __u8 rcvd_addr;
560 __u16 version;
561 __u16 minversion;
563 __u8 has_addr;
564 __be64 addr;
567 struct cor_ping_cookie {
568 ktime_t time_created;
569 ktime_t time_sent;
570 unsigned long jiffies_sent;
572 __u32 cookie;
573 __u8 pongs; /* count of pongs for pings sent after this one */
576 #define NEIGHBOR_STATE_INITIAL 0
577 #define NEIGHBOR_STATE_ACTIVE 1
578 #define NEIGHBOR_STATE_STALLED 2
579 #define NEIGHBOR_STATE_KILLED 3
581 #define NBCONGWIN_SHIFT 16
582 #define NBCONGWIN_MUL (1 << NBCONGWIN_SHIFT)
584 struct cor_neighbor {
585 struct list_head nb_list;
586 __u8 in_nb_list;
588 struct kref ref;
590 struct net_device *dev;
591 char mac[MAX_ADDR_LEN];
592 struct cor_dev *cd;
594 __be32 sessionid;
596 atomic_t sessionid_rcv_needed;
597 atomic_t sessionid_snd_needed;
599 __u8 has_addr;
600 __be64 addr;
602 atomic64_t cmsg_timer_timeout;
603 struct timer_list cmsg_timer;
604 spinlock_t cmsg_lock;
605 struct list_head cmsg_queue_pong;
606 struct list_head cmsg_queue_ack_fast;
607 struct list_head cmsg_queue_ack_slow;
608 struct list_head cmsg_queue_ackconn_urgent;
609 struct list_head cmsg_queue_ackconn;
610 struct list_head cmsg_queue_conndata_lowlat;
611 struct list_head cmsg_queue_conndata_highlat;
612 struct list_head cmsg_queue_other;
613 __u8 add_retrans_needed;
614 __u32 kpacket_seqno; /* not locked, only accessed by single tasklet */
616 struct rb_root pending_conn_resets_rb;
618 __u32 cmsg_pongslength;
619 __u32 cmsg_otherlength;
621 __u32 cmsg_pongscnt; /* size of queue only, protected by cmsg_lock */
622 atomic_t cmsg_pongs_retrans_cnt; /* number of retransmits only */
623 atomic_t cmsg_othercnt; /* size of queue + retransmits */
625 atomic_t cmsg_bulk_readds;
627 atomic_t cmsg_delay_conndata;
629 /* not locked, only accessed by single thread */
630 __u8 max_cmsg_delay_sent;
632 atomic_t rcvmtu_sendneeded;
635 /* procected by cor_dev send_queue->qlock */
636 struct cor_resume_block rb_kp;
637 struct cor_resume_block rb_cr;
638 struct cor_resume_block rb;
639 unsigned long cmsg_send_start_j;
640 ktime_t cmsg_send_start_kt;
642 struct{
643 spinlock_t lock;
644 struct list_head lh;
645 struct list_head lh_nextpass;
646 __u32 cnt;
647 __u64 priority_sum;
648 } conns_waiting;
650 struct{
651 spinlock_t lock;
654 * acked: avoid send bursts when data_intransit is shrunk too
655 * quickly
657 struct hrtimer acked_timer;
658 ktime_t acked_timeout_time;
659 ktime_t acked_refresh_time;
660 __u64 data_acked;
662 __u64 cwin_shrinkto;
664 atomic64_t data_intransit;
665 atomic64_t cwin;
667 } nbcongwin;
669 spinlock_t state_lock;
670 unsigned long last_ping_time;
671 struct cor_ping_cookie cookies[PING_COOKIES_PER_NEIGH];
672 __u32 ping_intransit;
673 __u32 lastcookie;
674 __u32 cookie_unsent;
675 __u64 latency_variance_retrans_us; /* microsecs */
676 atomic_t latency_retrans_us; /* microsecs */
677 atomic_t latency_stddev_retrans_us; /* microsecs */
678 atomic_t latency_advertised_us; /* microsecs */
679 __u8 rcvmtu_delayed_send_needed:1,
680 rcvmtu_allowed_countdown:2;
682 atomic_t max_remote_ack_fast_delay_us; /* microsecs */
683 atomic_t max_remote_ack_slow_delay_us; /* microsecs */
684 atomic_t max_remote_ackconn_delay_us; /* microsecs */
685 atomic_t max_remote_pong_delay_us; /* microsecs */
687 atomic_t remote_rcvmtu;
689 union {
690 unsigned long initial_state_since;/* initial state */
692 * last_roundtrip:
693 * time of the last sent packet which has been acked or
694 * otherwise responded to (e.g. pong)
696 unsigned long last_roundtrip;/* active/stalled state */
697 } state_time;
698 ktime_t last_roundtrip_end;
699 __u16 ping_success;
700 __u8 state;
702 __u8 str_timer_pending;
703 struct delayed_work stalltimeout_timer;
705 spinlock_t connid_lock;
706 struct rb_root connid_rb;
708 spinlock_t connid_reuse_lock;
709 struct rb_root connid_reuse_rb;
710 struct list_head connid_reuse_list;
711 __u16 connid_reuse_pingcnt;
712 __u8 connid_reuse_oom_countdown;
714 atomic64_t priority_sum;
717 * connecions which receive data from/send data to this node
718 * used when terminating all connections of a neighbor and terminating
719 * inactive connections
721 spinlock_t conn_list_lock;
722 struct list_head snd_conn_idle_list;
723 struct list_head snd_conn_busy_list;
726 * the timer has to be inited when adding the neighbor
727 * timer_setup(...);
728 * add_timer(struct timer_list * timer);
730 spinlock_t retrans_lock;
731 struct timer_list retrans_timer;
732 struct list_head retrans_fast_list;
733 struct list_head retrans_slow_list;
734 struct rb_root kp_retransmits_rb;
736 spinlock_t retrans_conn_lock;
737 struct timer_list retrans_conn_timer;
738 struct list_head retrans_conn_lowlatency_list;
739 struct list_head retrans_conn_highlatency_list;
741 struct work_struct reset_neigh_work;
744 static inline void cor_nb_kref_get(struct cor_neighbor *nb, char *reason)
746 /* printk(KERN_ERR "cor_nb_kref_get %p %s\n", nb, reason); */
747 kref_get(&nb->ref);
750 void cor_neighbor_free(struct kref *ref); /* neigh.c */
752 static inline void cor_nb_kref_put(struct cor_neighbor *nb, char *reason)
754 /* printk(KERN_ERR "cor_nb_kref_put %p %s\n", nb, reason); */
755 kref_put(&nb->ref, cor_neighbor_free);
758 void cor_kreffree_bug(struct kref *ref); /* util.c */
760 static inline void cor_nb_kref_put_bug(struct cor_neighbor *nb, char *reason)
762 /* printk(KERN_ERR "cor_nb_kref_put_bug %p %s\n", nb, reason); */
763 kref_put(&nb->ref, cor_kreffree_bug);
767 #define DATABUF_BUF 0
768 #define DATABUF_SKB 1
770 struct cor_data_buf_item {
771 struct list_head buf_list;
773 char *buf;
774 __u16 datalen;
775 __u16 buflen;
777 __u8 type;
780 struct cor_connid_reuse_item {
781 struct rb_node rbn;
783 struct list_head lh;
785 struct kref ref;
786 __u32 conn_id;
787 __u16 pingcnt;
790 #define SNDSPEED_INIT 0
791 #define SNDSPEED_ACTIVE 1
792 struct cor_snd_speed {
793 __u8 state;
794 __u8 flushed;
795 unsigned long jiffies_last_refresh;
796 __u32 bytes_sent;
798 /* bytes per second */
799 __u32 speed;
800 __u32 speed_limited;
803 struct cor_sock;
805 /* This struct helps keep struct cor_conn small. */
806 struct cor_conn_src_sock_extradata {
807 struct cor_conn *src_sock;
808 struct cor_sock *cs;
810 __u32 priority;
812 struct cor_snd_speed snd_speed;
815 * keepalive_lh and in_keepalive_list is protected by
816 * cor_keepalive_req_lock
818 struct timer_list keepalive_timer;
819 struct list_head keepalive_lh;
820 __u8 in_keepalive_list;
822 __be32 keepalive_req_cookie;
823 __be32 keepalive_resp_cookie;
825 * keepalive_intransit == 0... last resp received
826 * keepalive_intransit == 1... req sent
828 unsigned long jiffies_keepalive_lastact;
830 struct{
831 char snd_hdr[CONN_MNGD_HEADERLEN];
832 char snd_data[CONN_MNGD_MAX_CTRL_DATALEN];
833 char snd_chksum[CONN_MNGD_CHECKSUMLEN];
834 __u8 snd_data_len;
835 } buf_ctrl;
837 struct{
838 char snd_hdr[CONN_MNGD_HEADERLEN];
839 char snd_chksum[CONN_MNGD_CHECKSUMLEN];
840 char *snd_data;
841 __u16 snd_data_len;
842 } buf_data;
844 __u16 sent;
848 * There are 2 conn objects per bi-directional connection. They refer to each
849 * other with in the reversedir field.
853 * Naming:
855 * cn: conn we do not know what is inside
856 * src_in, trgt_unconn, trgt_out, ...: A conn with the specified source or
857 * targettype. In the unlocked case the types are only a guess, because they
858 * might have changed since the last access. After locking the
859 * source/destination parameters have to be checked whether they still are what
860 * we expect. This includes source/targettype, neighbor, conn_id
863 * Naming suffixes:
864 * no suffix: unlocked
866 * _l: this direction is locked
868 * _ll: both directions are locked
870 * _lx: this direction is locked, the other direction may be locked
872 * _o: unlocked, but source or target is known for sure, because an outside
873 * lock is taken; For variables on the heap this means that an outside lock must
874 * be taken before accessing the struct which points to the conn can be
875 * accessed.
878 * Most fields are protected by rcv_lock. Fields which which control
879 * source and destination of the data flow require both directions to
880 * to be locked and external references to be cleared before the change can
881 * happen. This includes fields like sourcetype, targettype, connid,
882 * list_heads, ???. In this case the side with is_client == 1 needs to be locked
883 * first.
885 * Some other fields are locked outside (e.g. at struct neighbor).
887 #define SOURCE_UNCONNECTED 0
888 #define SOURCE_IN 1
889 #define SOURCE_SOCK 2
891 #define TARGET_UNCONNECTED 0
892 #define TARGET_OUT 1
893 #define TARGET_SOCK 2
894 #define TARGET_DISCARD 3
896 #define BUFSIZE_NOACTION 0
897 #define BUFSIZE_DECR 1
898 #define BUFSIZE_DECR_FAST 2
899 #define BUFSIZE_INCR 3
900 #define BUFSIZE_INCR_FAST 4
902 #define JIFFIES_LAST_IDLE_SHIFT 8
903 #define BUFSIZE_SHIFT 3
905 #define SOCKTYPE_RAW 0
906 #define SOCKTYPE_MANAGED 1
908 #define RCV_BUF_STATE_OK 0
909 #define RCV_BUF_STATE_INCOMPLETE 1
910 #define RCV_BUF_STATE_RESET 2
912 #define SND_BUF_STATE_INCOMPLETE 0
913 #define SND_BUF_STATE_FILLED 1
916 struct cor_conn {
917 __u8 sourcetype:4,
918 targettype:4;
920 __u8 is_client; /* immutable after allocated */
923 * isreset values:
924 * 0... connection active
925 * 1... connection is about to be reset, target does not need to be
926 * notified
927 * 2... connection is reset
929 __u8 isreset;
931 __u8 flush:1,
932 is_highlatency:1,
933 is_highlatency_send_needed:1;
935 spinlock_t rcv_lock;
937 union{
938 struct{
939 struct cor_neighbor *nb;
941 struct list_head reorder_queue;
942 __u32 reorder_memused;
944 struct rb_node rbn;
945 __u32 conn_id;
946 __u32 next_seqno;
948 __u16 small_ooo_packets:14,
949 inorder_ack_needed:1,
950 established:1;
952 __u16 priority:12,
953 priority_seqno:4;
955 __u32 window_seqnolimit;
956 __u32 window_seqnolimit_remote;
958 /* protected by nb->cmsg_lock */
959 struct list_head acks_pending;
960 } in;
962 struct{
963 struct cor_conn_src_sock_extradata *ed;
966 * cl_list and in_cl_list is protected by cor_bindnodes
968 struct list_head cl_list;
969 __u8 in_cl_list;
971 /* protected by flushtoconn_oom_lock */
972 struct list_head flushtoconn_oom_lh;
973 /* protected by conn->rcv_lock */
974 __u8 in_flushtoconn_oom_list;
977 __u8 keepalive_intransit:1,
978 buf_ctrl_filled:1,
979 buf_data_filled:1,
980 send_keepalive_req_needed:1,
981 send_keepalive_resp_needed:1,
982 send_eof_needed:1,
983 send_rcvend_needed:1;
985 __u8 last_windowused;
986 __u8 flush:1,
987 socktype:1;
988 } sock;
989 } src;
991 union{
992 struct{
993 __u32 paramlen;
994 __u32 cmdread;
995 __u16 cmd;
996 __u8 paramlen_read;
997 char *cmdparams;
998 char paramlen_buf[4];
999 } unconnected;
1001 struct{
1002 struct cor_neighbor *nb;
1004 /* list of all connections to this neighbor */
1005 struct list_head nb_list;
1006 unsigned long jiffies_last_act;
1007 __u32 nblist_busy_remaining;
1009 __u32 conn_id;
1010 __u32 seqno_nextsend;
1011 __u32 seqno_acked;
1012 __u32 seqno_windowlimit;
1014 /* protected by nb->retrans_conn_lock, sorted by seqno
1016 struct list_head retrans_list;
1018 struct cor_resume_block rb;
1020 /* for bursting */
1021 unsigned long jiffies_idle_since;
1023 __u32 rb_priority;
1024 __u16 maxsend_extra;
1026 __u16 burst_bytes;
1028 __u8 lastsend_windowused;
1030 __u8 remote_bufsize_changerate;
1032 __u8 priority_send_allowed:1,
1033 established:1,
1034 in_nb_busy_list:1;
1036 __u16 priority_last:12,
1037 priority_seqno;
1039 /* protected by nb->retrans_conn_lock */
1040 __u16 retrans_lowwindow;
1041 } out;
1043 struct{
1044 __u8 waiting_for_userspace;
1045 unsigned long waiting_for_userspace_since;
1047 struct cor_sock *cs;
1049 __u8 socktype;
1051 __u8 rcv_buf_state;
1052 char rcv_hdr[CONN_MNGD_HEADERLEN];
1053 char rcv_chksum[CONN_MNGD_CHECKSUMLEN];
1054 char *rcv_buf;
1055 __u16 rcvd;
1056 __u16 rcv_hdr_flags;
1057 __u16 rcv_data_len;
1058 } sock;
1059 } trgt;
1061 struct{
1062 struct list_head items;
1063 struct cor_data_buf_item *nextread;
1064 __u32 first_offset;
1066 __u32 datasize;
1067 __u32 overhead;
1068 __u32 read_remaining;
1070 __u16 next_read_offset;
1071 } data_buf;
1073 __u32 bufspace_accounted;
1075 struct{
1076 __u32 bufsize; /* 8 ==> 1 byte, see BUFSIZE_SHIFT */
1077 __u32 ignore_rcv_lowbuf;
1078 union{
1079 struct{
1080 __u32 bytesleft;
1081 } noact;
1083 struct{
1084 __u32 size_start;
1085 } decr;
1087 struct{
1088 __u32 size_start;
1089 __u32 size_end;
1090 } incr;
1091 } act;
1093 __u32 state:3,
1094 bytes_rcvd:24;
1095 } bufsize;
1098 static inline __u32 cor_get_connid_reverse(__u32 conn_id)
1100 return conn_id ^ (1 << 31);
1103 struct cor_conn_bidir {
1104 struct cor_conn cli;
1105 struct cor_conn srv;
1107 struct kref ref;
1110 static inline struct cor_conn_bidir *cor_get_conn_bidir(struct cor_conn *cn)
1112 if (cn->is_client)
1113 return container_of(cn, struct cor_conn_bidir, cli);
1114 else
1115 return container_of(cn, struct cor_conn_bidir, srv);
1118 static inline struct cor_conn *cor_get_conn_reversedir(struct cor_conn *cn)
1120 if (cn->is_client) {
1121 struct cor_conn_bidir *cnb = container_of(cn,
1122 struct cor_conn_bidir, cli);
1123 return &cnb->srv;
1124 } else {
1125 struct cor_conn_bidir *cnb = container_of(cn,
1126 struct cor_conn_bidir, srv);
1127 return &cnb->cli;
1131 static inline void cor_conn_kref_get(struct cor_conn *cn, char *reason)
1133 /* printk(KERN_ERR "cor_conn_kref_get %p %s\n", cn, reason); */
1134 kref_get(&cor_get_conn_bidir(cn)->ref);
1137 void cor_free_conn(struct kref *ref); /* conn.c */
1139 static inline void cor_conn_kref_put(struct cor_conn *cn, char *reason)
1141 /* printk(KERN_ERR "cor_conn_kref_put %p %s\n", cn, reason); */
1142 kref_put(&cor_get_conn_bidir(cn)->ref, cor_free_conn);
1145 static inline void cor_conn_kref_put_bug(struct cor_conn *cn, char *reason)
1147 /* printk(KERN_ERR "cor_conn_kref_put_bug %p %s\n", cn, reason); */
1148 kref_put(&cor_get_conn_bidir(cn)->ref, cor_kreffree_bug);
1153 #define CONN_RETRANS_INITIAL 0
1154 #define CONN_RETRANS_SCHEDULED 1
1155 #define CONN_RETRANS_LOWWINDOW 2
1156 #define CONN_RETRANS_SENDING 3
1157 #define CONN_RETRANS_ACKED 4
1158 struct cor_conn_retrans {
1159 /* timeout_list and conn_list share a single ref */
1160 struct kref ref;
1161 /* only in timeout_list if state == CONN_RETRANS_SCHEDULED */
1162 struct list_head timeout_list;
1163 struct list_head conn_list;
1164 struct cor_conn *trgt_out_o;
1165 __u32 seqno;
1166 __u32 length;
1168 __u8 windowused;
1169 __u8 state;
1170 unsigned long timeout;
1173 #define RCVOOO_BUF 0
1174 #define RCVOOO_SKB 1
1175 struct cor_rcvooo {
1176 struct list_head lh;
1177 __u32 seqno;
1178 __u8 type;
1179 __u8 windowused;
1180 __u8 flush;
1183 struct cor_rcvooo_buf {
1184 struct cor_rcvooo r;
1185 char *data;
1186 __u32 len;
1189 /* inside skb->cb */
1190 struct cor_skb_procstate {
1191 union{
1192 struct{
1193 struct work_struct work;
1194 } announce1;
1196 struct{
1197 __u32 offset;
1198 } announce2;
1200 struct{
1201 __u32 skb_memused;
1202 struct cor_rcvooo r;
1203 } rcv_ooo;
1205 struct{
1206 struct cor_data_buf_item dbi;
1207 } rcv;
1208 } funcstate;
1211 #define CS_TYPE_UNCONNECTED 0
1212 #define CS_TYPE_LISTENER 1
1213 #define CS_TYPE_CONN_RAW 2
1214 #define CS_TYPE_CONN_MANAGED 3
1216 #define CS_CONNECTSTATE_UNCONNECTED 0
1217 #define CS_CONNECTSTATE_CONNECTING 1
1218 #define CS_CONNECTSTATE_CONNECTED 2
1219 #define CS_CONNECTSTATE_ERROR 3
1221 struct cor_sock {
1222 struct sock sk; /* must be first */
1224 struct mutex lock;
1225 struct kref ref;
1227 /* type may not change once it is set to != CS_TYPE_UNCONNECTED */
1228 __u8 type;
1229 __u8 isreleased;
1231 __u8 publish_service;
1233 __u8 is_highlatency;
1234 __u8 is_client;
1235 __u32 priority;
1237 union {
1238 struct {
1239 /* listener is protected by cor_bindnodes */
1240 struct list_head lh;
1241 __be32 port;
1242 __u8 publish_service;
1243 __u32 queue_maxlen;
1244 __u32 queue_len;
1245 struct list_head conn_queue;
1246 } listener;
1248 struct {
1249 struct cor_conn *src_sock;
1250 struct cor_conn *trgt_sock;
1252 struct cor_data_buf_item *rcvitem;
1253 __u16 rcvoffset;
1255 struct cor_sock *pass_on_close;
1256 } conn_raw;
1258 struct {
1259 struct cor_sockaddr remoteaddr;
1261 struct list_head rd_msgs;
1262 struct list_head crd_lh;
1263 __u8 in_crd_list;
1265 __u8 connect_state;
1267 __u8 is_reset;
1269 __u8 flush;
1271 __u8 shutdown_rd:1,
1272 shutdown_wr:1,
1273 sent_eof:1,
1274 sent_rcvend:1,
1275 rcvd_eof:1,
1276 rcvd_rcvend:1;
1278 __be64 cookie;
1279 struct rb_node rbn;
1281 struct cor_conn *src_sock;
1282 struct cor_conn *trgt_sock;
1284 /* sending */
1285 char *snd_buf;
1286 __u16 snd_segment_size;
1287 __u16 snd_data_len;
1288 __u8 send_in_progress;
1290 /* receiving */
1291 char *rcv_buf;
1292 __u16 rcv_data_len;
1293 __u16 rcvbuf_consumed;
1294 __u8 rcv_buf_state;
1295 } conn_managed;
1296 } data;
1298 struct work_struct readfromconn_work;
1299 atomic_t readfromconn_work_scheduled;
1301 atomic_t ready_to_read;
1302 atomic_t ready_to_write;
1303 atomic_t ready_to_accept;
1306 #define ACK_NEEDED_NO 0
1307 #define ACK_NEEDED_SLOW 1
1308 #define ACK_NEEDED_FAST 2
1310 /* config.c */
1311 extern spinlock_t cor_local_addr_lock;
1312 extern __u8 cor_local_has_addr;
1313 extern __be64 cor_local_addr;
1314 extern __be32 cor_local_addr_sessionid;
1316 int cor_is_device_configurated(struct net_device *dev);
1318 void cor_set_interface_config(struct cor_interface_config *new_config,
1319 __u32 new_num_interfaces, int new_all_interfaces);
1321 void cor_config_down(void);
1323 int cor_config_up(__u8 has_addr, __be64 addr);
1325 int cor_is_clientmode(void);
1327 /* dev.c */
1328 #ifdef DEBUG_QOS_SLOWSEND
1329 int _cor_dev_queue_xmit(struct sk_buff *skb, int caller);
1330 #else
1331 static inline int _cor_dev_queue_xmit(struct sk_buff *skb, int caller)
1333 return dev_queue_xmit(skb);
1335 #endif
1337 struct sk_buff *cor_create_packet_cmsg(struct cor_neighbor *nb, int size,
1338 gfp_t alloc_flags, __u32 seqno);
1340 struct sk_buff *cor_create_packet(struct cor_neighbor *nb, int size,
1341 gfp_t alloc_flags);
1343 struct sk_buff *cor_create_packet_conndata(struct cor_neighbor *nb, int size,
1344 gfp_t alloc_flags, __u32 conn_id, __u32 seqno, __u8 windowused,
1345 __u8 flush);
1347 void cor_dev_free(struct kref *ref);
1349 struct cor_dev *cor_dev_get(struct net_device *dev);
1351 void cor_dev_destroy(struct net_device *dev);
1353 void cor_dev_down(void);
1355 int cor_dev_up(void);
1357 int __init cor_dev_init(void);
1359 void __exit cor_dev_exit1(void);
1361 /* dev_queue.c */
1362 unsigned long cor_get_conn_idletime(struct cor_conn *trgt_out_lx);
1364 void cor_dev_queue_destroy(struct cor_dev *cd);
1366 int cor_dev_queue_init(struct cor_dev *cd);
1368 void cor_dev_queue_set_congstatus(struct cor_dev *cd_qlocked);
1370 void cor_dev_queue_set_lastdrop(struct cor_dev *cd);
1374 #define QOS_RESUME_DONE 0
1375 #define QOS_RESUME_CONG 1
1376 #define QOS_RESUME_NEXTNEIGHBOR 2 /* cor_resume_neighbors() internal */
1377 #define QOS_RESUME_EXIT 3
1379 #define QOS_CALLER_KPACKET 0
1380 #define QOS_CALLER_CONN_RETRANS 1
1381 #define QOS_CALLER_ANNOUNCE 2
1382 #define QOS_CALLER_NEIGHBOR 3
1384 void _cor_dev_queue_enqueue(struct cor_dev *cd, struct cor_resume_block *rb,
1385 unsigned long cmsg_send_start_j, ktime_t cmsg_send_start_kt,
1386 int caller, int from_nbcongwin_resume,
1387 int from_nbnotactive_resume);
1389 void cor_dev_queue_enqueue(struct cor_dev *cd, struct cor_resume_block *rb,
1390 unsigned long cmsg_send_start_j, ktime_t cmsg_send_start_kt,
1391 int caller, int from_nbnotactive_resume);
1393 void cor_qos_remove_conn(struct cor_conn *trgt_out_l);
1395 void cor_qos_enqueue_conn(struct cor_conn *trgt_out_lx);
1398 static inline int cor_dev_queue_xmit(struct sk_buff *skb,
1399 struct cor_dev *cd, int caller)
1401 int rc = _cor_dev_queue_xmit(skb, caller);
1403 if (unlikely(rc != NET_XMIT_SUCCESS))
1404 cor_dev_queue_set_lastdrop(cd);
1405 return rc;
1408 /* util.c */
1409 static inline __u16 cor_enc_priority(__u32 value)
1411 __u16 exponent = 0;
1412 __u16 mantissa;
1413 __u32 ret;
1415 while ((value >> exponent) > 255) {
1416 exponent++;
1418 BUG_ON(exponent > 15);
1420 mantissa = (value >> exponent);
1421 ret = (mantissa << 4) | exponent;
1422 BUG_ON(ret > 4095);
1423 return (__u16) ret;
1426 static inline __u32 cor_dec_priority(__u16 priority)
1428 __u32 mantissa = (__u32) (priority >> 4);
1429 __u16 exponent = (priority & 15);
1431 BUG_ON(priority > 4095);
1432 return (mantissa << exponent);
1435 static inline __u32 cor_priority_max(void)
1437 return cor_dec_priority(4095);
1440 __u8 __attribute__((const)) cor_enc_log_64_11(__u32 value);
1442 __u32 __attribute__((const)) cor_dec_log_64_11(__u8 value);
1444 void cor_swap_list_items(struct list_head *lh1, struct list_head *lh2);
1446 __u64 cor_update_atomic_sum(atomic64_t *atomic_sum, __u32 oldvalue,
1447 __u32 newvalue);
1449 int __init cor_util_init(void);
1453 /* neigh.c */
1454 extern atomic_t cor_num_neighs;
1456 int cor_is_from_nb(struct sk_buff *skb, struct cor_neighbor *nb);
1458 struct cor_neighbor *_cor_get_neigh_by_mac(struct net_device *dev,
1459 char *source_hw);
1461 struct cor_neighbor *cor_get_neigh_by_mac(struct sk_buff *skb);
1463 struct cor_neighbor *cor_find_neigh(__be64 addr);
1465 void cor_resend_rcvmtu(struct net_device *dev);
1467 __u32 cor_generate_neigh_list(char *buf, __u32 buflen);
1469 void cor_reset_neighbors(struct net_device *dev);
1471 int cor_get_neigh_state(struct cor_neighbor *nb);
1473 void cor_ping_resp(struct cor_neighbor *nb, __u32 cookie, __u32 respdelay);
1475 __u32 cor_add_ping_req(struct cor_neighbor *nb, unsigned long *last_ping_time);
1477 void cor_ping_sent(struct cor_neighbor *nb, __u32 cookie);
1479 void cor_unadd_ping_req(struct cor_neighbor *nb, __u32 cookie,
1480 unsigned long last_ping_time, int congested);
1482 #define TIMETOSENDPING_NO 0
1483 #define TIMETOSENDPING_YES 1
1484 #define TIMETOSENDPING_FORCE 2
1485 int cor_time_to_send_ping(struct cor_neighbor *nb);
1487 unsigned long cor_get_next_ping_time(struct cor_neighbor *nb);
1489 void cor_add_neighbor(struct cor_neighbor_discdata *nb_dd);
1491 struct cor_conn *cor_get_conn(struct cor_neighbor *nb, __u32 conn_id);
1493 int cor_insert_connid(struct cor_neighbor *nb, struct cor_conn *src_in_ll);
1495 void cor_insert_connid_reuse(struct cor_neighbor *nb, __u32 conn_id);
1497 int cor_connid_alloc(struct cor_neighbor *nb, struct cor_conn *src_in_ll);
1499 int __init cor_neighbor_init(void);
1501 void __exit cor_neighbor_exit2(void);
1503 /* neigh_ann_rcv.c */
1504 int cor_rcv_announce(struct sk_buff *skb);
1506 int __init cor_neigh_ann_rcv_init(void);
1508 void __exit cor_neigh_ann_rcv_exit2(void);
1510 /* neigh_ann_snd.c */
1511 int _cor_send_announce(struct cor_announce_data *ann, int fromqos, int *sent);
1513 void cor_announce_data_free(struct kref *ref);
1515 void cor_announce_send_start(struct net_device *dev, char *mac, int type);
1517 void cor_announce_send_stop(struct net_device *dev, char *mac, int type);
1519 /* neigh_rcv.c */
1520 void cor_kernel_packet(struct cor_neighbor *nb, struct sk_buff *skb,
1521 int ackneeded);
1523 /* neigh_snd.c */
1524 struct cor_control_msg_out;
1526 #define ACM_PRIORITY_LOW 1 /* oom recovery easy */
1527 #define ACM_PRIORITY_MED 2 /* oom may cause timeouts */
1528 #define ACM_PRIORITY_HIGH 3 /* cm acks - needed for freeing old cms */
1530 struct cor_control_msg_out *cor_alloc_control_msg(struct cor_neighbor *nb,
1531 int priority);
1533 void cor_free_control_msg(struct cor_control_msg_out *cm);
1535 void cor_retransmit_timerfunc(struct timer_list *retrans_timer);
1537 void cor_kern_ack_rcvd(struct cor_neighbor *nb, __u32 seqno);
1539 int cor_send_messages(struct cor_neighbor *nb, unsigned long cmsg_send_start_j,
1540 ktime_t cmsg_send_start_kt, int *sent);
1542 void cor_controlmsg_timerfunc(struct timer_list *cmsg_timer);
1544 void cor_schedule_controlmsg_timer(struct cor_neighbor *nb_cmsglocked);
1546 void cor_send_rcvmtu(struct cor_neighbor *nb);
1548 void cor_send_pong(struct cor_neighbor *nb, __u32 cookie, ktime_t ping_rcvtime);
1550 int cor_send_reset_conn(struct cor_neighbor *nb, __u32 conn_id, int lowprio);
1552 void cor_send_ack(struct cor_neighbor *nb, __u32 seqno, __u8 fast);
1554 void cor_send_ack_conn_ifneeded(struct cor_conn *src_in_l, __u32 seqno_ooo,
1555 __u32 ooo_length);
1557 void cor_send_priority(struct cor_conn *trgt_out_ll, __u16 priority);
1559 void cor_free_ack_conns(struct cor_conn *src_in_lx);
1561 void cor_send_connect_success(struct cor_control_msg_out *cm, __u32 conn_id,
1562 struct cor_conn *src_in);
1564 void cor_send_connect_nb(struct cor_control_msg_out *cm, __u32 conn_id,
1565 __u32 seqno1, __u32 seqno2, struct cor_conn *src_in_ll);
1567 void cor_send_conndata(struct cor_control_msg_out *cm, __u32 conn_id,
1568 __u32 seqno, char *data_orig, char *data, __u32 datalen,
1569 __u8 windowused, __u8 flush, __u8 highlatency,
1570 struct cor_conn_retrans *cr);
1572 int __init cor_kgen_init(void);
1574 void __exit cor_kgen_exit2(void);
1576 /* neigh_congwin.c */
1577 void cor_nbcongwin_data_retransmitted(struct cor_neighbor *nb,
1578 __u64 bytes_sent);
1580 enum hrtimer_restart cor_nbcongwin_hrtimerfunc(struct hrtimer *nb_congwin_timer);
1582 void cor_nbcongwin_data_acked(struct cor_neighbor *nb, __u64 bytes_acked);
1584 void cor_nbcongwin_data_sent(struct cor_neighbor *nb, __u32 bytes_sent);
1586 int cor_nbcongwin_send_allowed(struct cor_neighbor *nb);
1588 /* conn.c */
1589 extern struct kmem_cache *cor_connid_reuse_slab;
1591 extern atomic_t cor_num_conns;
1593 extern spinlock_t cor_bindnodes;
1595 int cor_new_incoming_conn_allowed(struct cor_neighbor *nb);
1597 __u32 _cor_conn_refresh_priority(struct cor_conn *cn_lx);
1599 __u32 cor_conn_refresh_priority(struct cor_conn *cn, int locked);
1601 void cor_set_conn_is_highlatency(struct cor_conn *cn, __u8 is_highlatency,
1602 int locked, int call_refresh_priority);
1604 void cor_set_conn_in_priority(struct cor_neighbor *nb, __u32 conn_id,
1605 struct cor_conn *src_in, __u8 priority_seqno, __u16 priority,
1606 __u8 is_highlatency);
1608 void cor_conn_set_last_act(struct cor_conn *trgt_out_lx);
1610 int cor_conn_init_out(struct cor_conn *trgt_unconn_ll, struct cor_neighbor *nb,
1611 __u32 rcvd_connid, int use_rcvd_connid);
1613 int cor_conn_init_sock_source(struct cor_conn *cn);
1615 void cor_conn_init_sock_target(struct cor_conn *cn);
1617 __u32 cor_list_services(char *buf, __u32 buflen);
1619 void cor_set_publish_service(struct cor_sock *cs, __u8 value);
1621 void cor_close_port(struct cor_sock *cs);
1623 int cor_open_port(struct cor_sock *cs_l, __be32 port);
1625 #define CONNECT_PORT_OK 0
1626 #define CONNECT_PORT_PORTCLOSED 1
1627 #define CONNECT_PORT_TEMPORARILY_OUT_OF_RESOURCES 2
1629 int cor_connect_port(struct cor_conn *trgt_unconn_ll, __be32 port);
1631 int cor_connect_neigh(struct cor_conn *trgt_unconn_ll, __be64 addr);
1633 struct cor_conn_bidir *cor_alloc_conn(gfp_t allocflags, __u8 is_highlatency);
1635 void cor_reset_conn_locked(struct cor_conn_bidir *cnb_ll);
1637 void cor_reset_conn(struct cor_conn *cn);
1639 /* conn_src_in.c */
1640 void cor_reset_ooo_queue(struct cor_conn *src_in_lx);
1642 void cor_drain_ooo_queue(struct cor_conn *src_in_l);
1644 void cor_conn_rcv(struct cor_neighbor *nb, struct sk_buff *skb, char *data,
1645 __u32 len, __u32 conn_id, __u32 seqno, __u8 windowused,
1646 __u8 flush);
1648 int __init cor_rcv_init(void);
1650 void __exit cor_rcv_exit2(void);
1652 /* conn_src_sock.c */
1653 void cor_update_src_sock_sndspeed(struct cor_conn *src_sock_l,
1654 __u32 bytes_sent);
1656 int cor_sock_sndbufavailable(struct cor_conn *src_sock_lx, int for_wakeup);
1658 #define RC_FTC_OK 0
1659 #define RC_FTC_OOM 1
1660 #define RC_FTC_ERR 2
1661 int _cor_mngdsocket_flushtoconn(struct cor_conn *src_sock_l);
1663 int cor_mngdsocket_flushtoconn_ctrl(struct cor_sock *cs_m_l, __u8 send_eof,
1664 __u8 send_rcvend, __u8 send_keepalive_resp,
1665 __be32 keepalive_resp_cookie);
1667 int cor_mngdsocket_flushtoconn_data(struct cor_sock *cs_m_l);
1669 void cor_keepalive_req_timerfunc(struct timer_list *retrans_conn_timer);
1671 void cor_keepalive_req_sched_timer(struct cor_conn *src_sock_lx);
1673 void cor_keepalive_resp_rcvd(struct cor_sock *cs_m_l, __be32 cookie);
1675 int __init cor_conn_src_sock_init1(void);
1677 void __exit cor_conn_src_sock_exit1(void);
1679 /* conn_trgt_unconn.c */
1680 int cor_encode_len(char *buf, int buflen, __u32 len);
1682 void cor_proc_cpacket(struct cor_conn *trgt_unconn);
1684 /* conn_trgt_out.c */
1685 void cor_free_connretrans(struct kref *ref);
1687 void cor_reschedule_conn_retrans_timer(struct cor_neighbor *nb_retranslocked);
1689 void cor_cancel_all_conn_retrans(struct cor_conn *trgt_out_l);
1691 int cor_send_retrans(struct cor_neighbor *nb, int *sent);
1693 void cor_retransmit_conn_timerfunc(struct timer_list *retrans_timer_conn);
1695 void cor_conn_ack_ooo_rcvd(struct cor_neighbor *nb, __u32 conn_id,
1696 struct cor_conn *trgt_out, __u32 seqno_ooo, __u32 length,
1697 __u64 *bytes_acked);
1699 void cor_conn_ack_rcvd(struct cor_neighbor *nb, __u32 conn_id,
1700 struct cor_conn *trgt_out, __u32 seqno, int setwindow,
1701 __u8 window, __u8 bufsize_changerate, __u64 *bytes_acked);
1703 void cor_schedule_retransmit_conn(struct cor_conn_retrans *cr, int connlocked,
1704 int nbretrans_locked);
1706 int cor_srcin_buflimit_reached(struct cor_conn *src_in_lx);
1708 /* RC_FLUSH_CONN_OUT_SENT | RC_FLUSH_CONN_OUT_{^SENT} */
1709 #define RC_FLUSH_CONN_OUT_OK 1
1710 #define RC_FLUSH_CONN_OUT_SENT_CONG 2 /* cor_flush_out internal only */
1711 #define RC_FLUSH_CONN_OUT_NBNOTACTIVE 3
1712 #define RC_FLUSH_CONN_OUT_CONG 4
1713 #define RC_FLUSH_CONN_OUT_MAXSENT 5
1714 #define RC_FLUSH_CONN_OUT_OOM 6
1716 int _cor_flush_out(struct cor_conn *trgt_out_lx, __u32 maxsend, __u32 *sent,
1717 int from_qos, int maxsend_forcedelay);
1719 static inline int cor_flush_out(struct cor_conn *trgt_out_lx, __u32 *sent)
1721 int rc = _cor_flush_out(trgt_out_lx, 1 << 30, sent, 0, 0);
1723 if (rc == RC_FLUSH_CONN_OUT_CONG || rc == RC_FLUSH_CONN_OUT_MAXSENT ||
1724 rc == RC_FLUSH_CONN_OUT_OOM ||
1725 rc == RC_FLUSH_CONN_OUT_NBNOTACTIVE)
1726 cor_qos_enqueue_conn(trgt_out_lx);
1728 return rc;
1731 int __init cor_snd_init(void);
1733 void __exit cor_snd_exit2(void);
1735 /* conn_trgt_sock.c */
1736 void cor_flush_sock_managed(struct cor_conn *trgt_sock_lx, int from_recvmsg,
1737 __u8 *do_wake_sender);
1739 void cor_flush_sock(struct cor_conn *trgt_sock_lx);
1741 /* conn_databuf.c */
1742 extern struct kmem_cache *cor_data_buf_item_slab;
1744 void cor_databuf_init(struct cor_conn *cn_init);
1746 void cor_bufsize_init(struct cor_conn *cn_l, __u32 bufsize);
1748 int cor_account_bufspace(struct cor_conn *cn_lx);
1750 int cor_conn_src_unconn_write_allowed(struct cor_conn *src_unconn_lx);
1752 void cor_update_windowlimit(struct cor_conn *src_in_lx);
1754 __u8 _cor_bufsize_update_get_changerate(struct cor_conn *cn_lx);
1756 static inline int cor_bufsize_initial_phase(struct cor_conn *cn_lx)
1758 return unlikely(cn_lx->bufsize.bytes_rcvd != (1 << 24) - 1 &&
1759 cn_lx->bufsize.bytes_rcvd < cn_lx->bufsize.bufsize);
1762 static inline int cor_ackconn_urgent(struct cor_conn *cn_lx)
1764 return cor_bufsize_initial_phase(cn_lx) ||
1765 cn_lx->bufsize.state == BUFSIZE_INCR_FAST;
1768 void cor_bufsize_read_to_sock(struct cor_conn *trgt_sock_lx);
1770 void cor_databuf_ackdiscard(struct cor_conn *cn_lx);
1772 void cor_reset_seqno(struct cor_conn *cn_l, __u32 initseqno);
1774 void cor_databuf_pull(struct cor_conn *cn_lx, char *dst, __u32 len);
1776 static inline __u32 cor_databuf_trypull(struct cor_conn *cn_l, char *dst,
1777 __u32 len)
1779 if (len > cn_l->data_buf.read_remaining)
1780 len = cn_l->data_buf.read_remaining;
1781 cor_databuf_pull(cn_l, dst, len);
1782 return len;
1785 void cor_databuf_unpull_dpi(struct cor_conn *trgt_sock, struct cor_sock *cs,
1786 struct cor_data_buf_item *item, __u16 next_read_offset);
1788 void cor_databuf_pull_dbi(struct cor_sock *cs_rl, struct cor_conn *trgt_sock_l);
1790 void cor_databuf_unpull(struct cor_conn *trgt_out_l, __u32 bytes);
1792 void cor_databuf_pullold(struct cor_conn *trgt_out_l, __u32 startpos, char *dst,
1793 int len);
1795 void cor_databuf_ack(struct cor_conn *trgt_out_l, __u32 pos);
1797 void cor_databuf_ackread(struct cor_conn *cn_lx);
1799 __u32 _cor_receive_buf(struct cor_conn *cn_lx, char *buf, __u32 datalen,
1800 int from_sock, __u8 windowused, __u8 flush);
1802 static inline __u32 cor_receive_buf(struct cor_conn *cn_lx, char *buf,
1803 __u32 datalen, __u8 windowused, __u8 flush)
1805 return _cor_receive_buf(cn_lx, buf, datalen, 0, windowused, flush);
1808 static inline __u32 cor_receive_sock(struct cor_conn *src_sock_l, char *buf,
1809 __u32 datalen, __u8 flush)
1811 __u32 ret;
1813 BUG_ON(src_sock_l->sourcetype != SOURCE_SOCK);
1815 ret = _cor_receive_buf(src_sock_l, buf, datalen, 1,
1816 src_sock_l->src.sock.last_windowused, flush);
1818 if (likely(ret > 0)) {
1819 __u32 bufsize = src_sock_l->bufsize.bufsize >> BUFSIZE_SHIFT;
1820 __u32 bufused = src_sock_l->data_buf.read_remaining;
1822 if (bufused >= bufsize)
1823 src_sock_l->src.sock.last_windowused = 31;
1824 else if (unlikely(bufused * 31 > U32_MAX))
1825 src_sock_l->src.sock.last_windowused =
1826 bufused / ((bufsize + 30) / 31);
1827 else
1828 src_sock_l->src.sock.last_windowused =
1829 (bufused * 31) / bufsize;
1832 return ret;
1835 __u32 cor_receive_skb(struct cor_conn *src_in_l, struct sk_buff *skb,
1836 __u8 windowused, __u8 flush);
1838 void cor_wake_sender(struct cor_conn *cn);
1840 int __init cor_forward_init(void);
1842 void __exit cor_forward_exit2(void);
1844 /* sock.c */
1845 void cor_free_sock(struct kref *ref);
1847 int cor_socket_setsockopt_tos(struct socket *sock, char __user *optval,
1848 unsigned int optlen);
1850 int cor_socket_setsockopt_priority(struct socket *sock, char __user *optval,
1851 unsigned int optlen);
1853 int cor_socket_socketpair(struct socket *sock1, struct socket *sock2);
1855 int cor_socket_getname(struct socket *sock, struct sockaddr *addr, int peer);
1857 int cor_socket_mmap(struct file *file, struct socket *sock,
1858 struct vm_area_struct *vma);
1860 int _cor_createsock(struct net *net, struct socket *sock, int protocol,
1861 int kern, __u8 is_client);
1863 int __init cor_sock_init1(void);
1865 int __init cor_sock_init2(void);
1867 void __exit cor_sock_exit1(void);
1869 /* sock_rdaemon.c */
1870 int cor_is_device_configurated(struct net_device *dev);
1872 int cor_create_rdaemon_sock(struct net *net, struct socket *sock, int protocol,
1873 int kern);
1875 int cor_rdreq_connect(struct cor_sock *cs);
1877 void cor_usersock_release(struct cor_sock *cs);
1879 int __init cor_rd_init1(void);
1881 int __init cor_rd_init2(void);
1883 void __exit cor_rd_exit1(void);
1885 void __exit cor_rd_exit2(void);
1887 /* sock_raw.c */
1888 int cor_create_raw_sock(struct net *net, struct socket *sock, int protocol,
1889 int kern);
1891 /* sock_managed.c */
1892 struct cor_sock *cor_get_sock_by_cookie(__be64 cookie);
1894 void __cor_set_sock_connecterror(struct cor_sock *cs_m_l, int errorno);
1896 void _cor_set_sock_connecterror(struct cor_sock *cs, int errorno);
1898 void cor_mngdsocket_chksum(char *hdr, __u32 hdrlen, char *data, __u32 datalen,
1899 char *chksum, __u32 chksum_len);
1901 static inline void cor_set_sock_connecterror(__be64 cookie, int errorno)
1903 struct cor_sock *cs = cor_get_sock_by_cookie(cookie);
1905 if (cs != 0) {
1906 _cor_set_sock_connecterror(cs, errorno);
1907 kref_put(&cs->ref, cor_free_sock);
1911 void cor_mngdsocket_readfromconn_fromatomic(struct cor_sock *cs);
1913 void cor_mngdsocket_readfromconn_wq(struct work_struct *work);
1915 int cor_create_managed_sock(struct net *net, struct socket *sock, int protocol,
1916 int kern);
1918 int __init cor_sock_managed_init1(void);
1921 static inline struct cor_skb_procstate *cor_skb_pstate(struct sk_buff *skb)
1923 BUILD_BUG_ON(sizeof(struct cor_skb_procstate) > sizeof(skb->cb));
1924 return (struct cor_skb_procstate *) &skb->cb[0];
1927 static inline struct sk_buff *cor_skb_from_pstate(struct cor_skb_procstate *ps)
1929 return (struct sk_buff *) (((char *)ps) - offsetof(struct sk_buff, cb));
1932 static inline int cor_qos_fastsend_allowed_conn_retrans(struct cor_neighbor *nb)
1934 return atomic_read(&nb->cd->send_queue.cong_status) < CONGSTATUS_RETRANS;
1937 static inline int cor_qos_fastsend_allowed_announce(struct net_device *dev)
1939 int rc;
1940 struct cor_dev *cd = cor_dev_get(dev);
1942 if (cd == 0)
1943 return 0;
1945 rc = atomic_read(&cd->send_queue.cong_status) < CONGSTATUS_ANNOUNCE;
1947 kref_put(&cd->ref, cor_dev_free);
1949 return rc;
1952 static inline int cor_qos_fastsend_allowed_conn(struct cor_conn *trgt_out_lx)
1954 struct cor_dev *cd = trgt_out_lx->trgt.out.nb->cd;
1956 return atomic_read(&cd->send_queue.cong_status) < CONGSTATUS_CONNDATA;
1959 static inline __u32 cor_rcv_mtu(struct cor_neighbor *nb)
1961 return nb->dev->mtu;
1964 static inline __u32 cor_snd_mtu(struct cor_neighbor *nb)
1966 return min((__u32) nb->dev->mtu,
1967 (__u32) atomic_read(&nb->remote_rcvmtu));
1970 static inline __u32 cor_mss(struct cor_neighbor *nb, __u32 l3overhead)
1972 return cor_snd_mtu(nb) - LL_RESERVED_SPACE(nb->dev) - l3overhead;
1975 static inline __u32 cor_mss_cmsg(struct cor_neighbor *nb)
1977 return cor_mss(nb, 5);
1980 static inline __u32 cor_mss_conndata(struct cor_neighbor *nb, int highlatency)
1982 __u32 mss_tmp = cor_mss(nb, 9);
1983 __u32 i;
1985 if (mss_tmp < 256 || highlatency || LOWLATENCY_LOWERMTU == 0)
1986 return mss_tmp;
1988 for (i = 256; i < 4096; i *= 2) {
1989 if (i * 2 > mss_tmp)
1990 return i;
1993 return mss_tmp - mss_tmp % 4096;
1996 static inline __u32 cor_send_conndata_as_skb(struct cor_neighbor *nb,
1997 __u32 size)
1999 return size >= cor_mss_conndata(nb, 0) / 2 ||
2000 size > KP_CONN_DATA_MAXLEN;
2003 static inline long cor_calc_timeout(__u32 latency_us, __u32 latency_stddev_us,
2004 __u32 max_remote_ack_delay_us)
2006 unsigned long addto;
2008 if (unlikely(unlikely(latency_us > 1000000000) ||
2009 unlikely(latency_stddev_us > 500000000) ||
2010 unlikely(max_remote_ack_delay_us > 1000000000))) {
2011 addto = msecs_to_jiffies(latency_us / 1000 + latency_us / 4000 +
2012 latency_stddev_us / 333 +
2013 max_remote_ack_delay_us / 1000);
2014 } else {
2015 addto = usecs_to_jiffies(latency_us + latency_us / 4 +
2016 latency_stddev_us * 3 +
2017 max_remote_ack_delay_us);
2021 * 2 is added because
2022 * 1) _to_jiffies rounds down, but should round up, so add 1 to
2023 * compensate
2024 * 2) even if latency is 0, we never want to schedule the retransmit
2025 * to run right now, so add 1 more
2027 return jiffies + 2 + addto;
2030 static inline void cor_put_be64(char *dst, __be64 value)
2032 char *p_value = (char *) &value;
2034 dst[0] = p_value[0];
2035 dst[1] = p_value[1];
2036 dst[2] = p_value[2];
2037 dst[3] = p_value[3];
2038 dst[4] = p_value[4];
2039 dst[5] = p_value[5];
2040 dst[6] = p_value[6];
2041 dst[7] = p_value[7];
2044 static inline void cor_put_u64(char *dst, __u64 value)
2046 cor_put_be64(dst, cpu_to_be64(value));
2049 static inline void cor_put_be32(char *dst, __be32 value)
2051 char *p_value = (char *) &value;
2053 dst[0] = p_value[0];
2054 dst[1] = p_value[1];
2055 dst[2] = p_value[2];
2056 dst[3] = p_value[3];
2059 static inline void cor_put_u32(char *dst, __u32 value)
2061 cor_put_be32(dst, cpu_to_be32(value));
2064 static inline void cor_put_be16(char *dst, __be16 value)
2066 char *p_value = (char *) &value;
2068 dst[0] = p_value[0];
2069 dst[1] = p_value[1];
2072 static inline void cor_put_u16(char *dst, __u16 value)
2074 cor_put_be16(dst, cpu_to_be16(value));
2077 static inline char *cor_pull_skb(struct sk_buff *skb, unsigned int len)
2079 char *ptr = skb_pull(skb, len);
2081 if (unlikely(ptr == 0))
2082 return 0;
2084 return ptr - len;
2087 static inline __be64 cor_parse_be64(char *buf)
2089 __be64 ret = 0;
2091 BUG_ON(buf == 0);
2093 ((char *)&ret)[0] = buf[0];
2094 ((char *)&ret)[1] = buf[1];
2095 ((char *)&ret)[2] = buf[2];
2096 ((char *)&ret)[3] = buf[3];
2097 ((char *)&ret)[4] = buf[4];
2098 ((char *)&ret)[5] = buf[5];
2099 ((char *)&ret)[6] = buf[6];
2100 ((char *)&ret)[7] = buf[7];
2102 return ret;
2105 static inline __u64 cor_parse_u64(char *buf)
2107 return be64_to_cpu(cor_parse_be64(buf));
2110 static inline __be32 cor_parse_be32(char *ptr)
2112 __be32 ret = 0;
2114 BUG_ON(ptr == 0);
2116 ((char *)&ret)[0] = ptr[0];
2117 ((char *)&ret)[1] = ptr[1];
2118 ((char *)&ret)[2] = ptr[2];
2119 ((char *)&ret)[3] = ptr[3];
2121 return ret;
2124 static inline __u32 cor_parse_u32(char *ptr)
2126 return be32_to_cpu(cor_parse_be32(ptr));
2129 static inline __be16 cor_parse_be16(char *ptr)
2131 __be16 ret = 0;
2133 BUG_ON(ptr == 0);
2135 ((char *)&ret)[0] = ptr[0];
2136 ((char *)&ret)[1] = ptr[1];
2138 return ret;
2141 static inline __u16 cor_parse_u16(char *ptr)
2143 return be16_to_cpu(cor_parse_be16(ptr));
2146 static inline __u8 cor_parse_u8(char *ptr)
2148 BUG_ON(ptr == 0);
2149 return (__u8) ptr[0];
2152 static inline __be32 cor_pull_be32(struct sk_buff *skb)
2154 return cor_parse_be32(cor_pull_skb(skb, 4));
2157 static inline __u32 cor_pull_u32(struct sk_buff *skb)
2159 return cor_parse_u32(cor_pull_skb(skb, 4));
2162 static inline __u16 cor_pull_u16(struct sk_buff *skb)
2164 return cor_parse_u16(cor_pull_skb(skb, 2));
2167 static inline __u8 cor_pull_u8(struct sk_buff *skb)
2169 char *ptr = cor_pull_skb(skb, 1);
2171 BUG_ON(ptr == 0);
2172 return *ptr;
2175 static inline int cor_is_conn_in(struct cor_conn *cn_l, struct cor_neighbor *nb,
2176 __u32 conn_id)
2178 if (unlikely(unlikely(cn_l->sourcetype != SOURCE_IN) ||
2179 unlikely(cn_l->src.in.nb != nb) ||
2180 unlikely(cn_l->src.in.conn_id != conn_id) ||
2181 unlikely(cn_l->isreset != 0)))
2182 return 0;
2183 return 1;
2186 static inline int cor_is_src_sock(struct cor_conn *cn_l, struct cor_sock *cs)
2188 if (unlikely(unlikely(cn_l->sourcetype != SOURCE_SOCK) ||
2189 unlikely(cn_l->src.sock.ed->cs != cs)))
2190 return 0;
2191 return 1;
2194 static inline int cor_is_trgt_sock(struct cor_conn *cn_l, struct cor_sock *cs)
2196 if (unlikely(unlikely(cn_l->targettype != TARGET_SOCK) ||
2197 unlikely(cn_l->trgt.sock.cs != cs)))
2198 return 0;
2199 return 1;
2202 #define BUFLEN_MIN 128
2203 #define BUFLEN_MAX 4096
2204 #define PAGESIZE (1 << PAGE_SHIFT)
2206 static inline __u32 cor_buf_optlen(__u32 datalen, int from_sock)
2208 __u32 optlen = BUFLEN_MIN;
2210 if (from_sock)
2211 return BUFLEN_MAX;
2213 while (optlen < datalen && optlen < PAGESIZE && optlen < BUFLEN_MAX)
2214 optlen = (optlen << 1);
2215 return optlen;
2219 static inline void cor_databuf_item_free(struct cor_data_buf_item *item)
2221 if (item->type == DATABUF_BUF) {
2222 kfree(item->buf);
2223 kmem_cache_free(cor_data_buf_item_slab, item);
2224 } else if (item->type == DATABUF_SKB) {
2225 struct sk_buff *skb = cor_skb_from_pstate(container_of(item,
2226 struct cor_skb_procstate, funcstate.rcv.dbi));
2227 kfree_skb(skb);
2228 } else {
2229 BUG();
2233 static inline int cor_seqno_eq(__u32 seqno1, __u32 seqno2)
2235 return seqno1 == seqno2;
2238 static inline int cor_seqno_before(__u32 seqno1, __u32 seqno2)
2240 return (seqno1 - seqno2) >= (1LL << 31);
2243 static inline int cor_seqno_before_eq(__u32 seqno1, __u32 seqno2)
2245 return cor_seqno_eq(seqno1, seqno2) || cor_seqno_before(seqno1, seqno2);
2248 static inline int cor_seqno_after(__u32 seqno1, __u32 seqno2)
2250 return cor_seqno_before_eq(seqno1, seqno2) ? 0 : 1;
2253 static inline int cor_seqno_after_eq(__u32 seqno1, __u32 seqno2)
2255 return cor_seqno_before(seqno1, seqno2) ? 0 : 1;
2258 static inline int ktime_before_eq(ktime_t time1, ktime_t time2)
2260 return ktime_after(time1, time2) ? 0 : 1;
2263 static inline int ktime_after_eq(ktime_t time1, ktime_t time2)
2265 return ktime_before(time1, time2) ? 0 : 1;
2269 static inline void cor_sk_write_space(struct cor_sock *cs)
2271 atomic_set(&cs->ready_to_write, 1);
2272 barrier();
2273 cs->sk.sk_write_space(&cs->sk);
2276 static inline void cor_sk_data_ready(struct cor_sock *cs)
2278 atomic_set(&cs->ready_to_read, 1);
2279 barrier();
2280 cs->sk.sk_data_ready(&cs->sk);
2283 /* the other direction may be locked only if called from cor_proc_cpacket */
2284 static inline void cor_flush_buf(struct cor_conn *cn_lx)
2286 if (unlikely(cn_lx->targettype == TARGET_UNCONNECTED)) {
2287 cor_proc_cpacket(cn_lx);
2288 } else if (cn_lx->targettype == TARGET_SOCK) {
2289 cor_flush_sock(cn_lx);
2290 } else if (cn_lx->targettype == TARGET_OUT) {
2291 __u32 bytessent = 0;
2293 cor_flush_out(cn_lx, &bytessent);
2294 } else if (unlikely(cn_lx->targettype == TARGET_DISCARD)) {
2295 cor_databuf_ackdiscard(cn_lx);
2296 } else {
2297 BUG();