2 * Connection oriented routing
3 * Copyright (C) 2007-2019 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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include <asm/atomic.h>
23 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/interrupt.h>
26 #include <linux/sched.h>
27 #include <linux/netdevice.h>
28 #include <linux/skbuff.h>
29 #include <linux/spinlock.h>
30 #include <linux/workqueue.h>
31 #include <linux/kref.h>
32 #include <linux/ktime.h>
33 #include <linux/rbtree.h>
35 #include <linux/socket.h>
38 #include <linux/math64.h>
43 #define ETH_P_COR 0x1022
47 #define PROTO_COR_RAW 0
48 #define PROTO_COR_RDEAMON 1
50 #define SOCKADDRTYPE_PORT 1
51 #define SOCKADDRTYPE_ADDRPORT 2
59 #define COR_PASS_ON_CLOSE 1
60 #define COR_PUBLISH_SERVICE 2
62 #define MAX_CONN_CMD_LEN 64
65 #define PACKET_TYPE_ANNOUNCE 1
66 #define PACKET_TYPE_CMSG 2
67 #define PACKET_TYPE_CONNDATA 4
68 #define PACKET_TYPE_CONNDATA_LOWBUFDELAYED 5
69 #define PACKET_TYPE_CONNDATA_FLUSH 6
70 #define PACKET_TYPE_CONNDATA_LOWBUFDELAYED_FLUSH 7
73 * Kernel packet data - these commands are sent by the neighbor
74 * The end nodes may cause these commands to be sent, but they see them beyond
82 * KP_INIT_SESSION[1] sessionid[4]
84 * finishes neighbor discovery and starts a session
86 * Before this is received all other commands are ignored. The sessionid is used
87 * to prevent usage of old neighbor discovery data (e.g. addresses)
89 #define KP_INIT_SESSION 1
92 * KP_PING[1] cookie[4]
93 * KP_PONG[1] cookie[4] respdelay[4]
95 * This is needed to find out whether the other node is reachable. After a new
96 * neighbor is seen, ping requests are sent and the neighbor is only reachable
97 * after a few pongs are received. These requests are also used to find out
98 * whether a neighber is gone.
101 * The receiver of a ping may delay the sending of the pong e.g. to create
102 * bigger packets. The respdelay is the time in microseconds the packet was
108 /* KP_ACK[1] seqno[6] */
112 * KP_ACK_CONN[1] conn_id[4] flags[1] seqno[6] window[1] seqno_ooo[6]
113 * length[1-4] priority_seqno[1] priority[1]
115 * conn_id is the conn_id we use if we sent something through this conn and
116 * *not* the conn_id that the neighbor used to send us the data
118 * flags defines which of the following fields are sent
120 * seqno = the seqno which is expected in the next non-out-of-order packet
122 * window = amount of data which can be sent without receiving the next ack
123 * packets with lower seqno do not overwrite the last window size
124 * The window may also be reduced. However, this only indicates a wish.
125 * Packets must be accepted if they exceed the new window, but not the old
130 * 1...255 = 64*2^((value-1)/7) end result is rounded down to an integer
132 * seqno_ooo, length = This packet was received out of order. Maybe a previous
133 * packet has been lost. Out of order data should not be retransmitted.
134 * Multiple ooo packets may be merged into a single ack. Ooo packets may be
135 * partially accepted, so that the length does not cover the full packet and/
136 * or the seqno starts in the middle of a packet
138 #define KP_ACK_CONN 5
140 #define KP_ACK_CONN_FLAGS_SEQNO 1
141 #define KP_ACK_CONN_FLAGS_WINDOW 2
142 #define KP_ACK_CONN_FLAGS_OOO 12 /* 4+8 */
143 #define KP_ACK_CONN_FLAGS_PRIORITY 16
145 static inline __u8
ooolen_to_flags(__u32 len
)
156 static inline int ooolen(__u8 flags
)
158 int len
= ((flags
& KP_ACK_CONN_FLAGS_OOO
) >> 2);
159 if (unlikely(len
== 3))
164 static inline int ack_conn_len(__u8 flags
)
167 if ((flags
& KP_ACK_CONN_FLAGS_SEQNO
) != 0) {
169 if ((flags
& KP_ACK_CONN_FLAGS_WINDOW
) != 0)
173 if (ooolen(flags
) != 0) {
175 len
+= ooolen(flags
);
178 if (flags
& KP_ACK_CONN_FLAGS_PRIORITY
)
185 * NOTE on connection ids:
186 * connection ids we receive with most significant bit 0 have been generated by
188 * connection ids we receive with most significant bit 1 have been generated by
191 * ATTENTION: the priority seqno are reversed:
192 * priority seqnos we send are used when we send updates
193 * priority seqnos we received are used when we receive updates
197 * incoming connection
198 * seqno1... used to ack data sent from the side which initiated the connection
199 * seqno2... used to ack data sent to the side which initiated the connection
200 * KP_CONNECT[1] conn_id[4] seqno1[6] seqno2[6] window[1] priority_seqno[1]
206 * incoming connection successful,
207 * KP_CONNECT_SUCCESS[1] conn_id[4] window[1]
209 #define KP_CONNECT_SUCCESS 7
211 /* KP_CONN_DATA[1] conn_id[4] seqno[6] length[2] data[length] */
212 #define KP_CONN_DATA 8
213 #define KP_CONN_DATA_LOWBUFDELAYED 9
214 #define KP_CONN_DATA_FLUSH 10
215 #define KP_CONN_DATA_LOWBUFDELAYED_FLUSH 11
218 * KP_RESET_CONN[1] conn_id[4]
219 * We send this, if there is an established connection we want to close.
221 #define KP_RESET_CONN 12
224 * KP_SET_MAX_CMSG_DELAY[1] cpacket_ack_delay[4] data_ack_delay[4] cmsg_delay[4]
225 * Sent after connecting and at any change
226 * delay in specifies in microsecs
228 #define KP_SET_MAX_CMSG_DELAY 13
232 * Connection data which in interpreted when connection has no target yet
233 * These commands are sent by the end node.
236 * cmd[2] length[1-4] parameter[length]
237 * unrecogniced commands are ignored
238 * parameters which are longer than expected are ignored as well
241 #define CD_CONTINUE_ON_ERROR_FLAG 32768
243 /* outgoing connection: CD_CONNECT_NB[2] length[1-4]
244 * addrlen[1-4] addr[addrlen] */
245 #define CD_CONNECT_NB 1
247 /* connection to local open part: CD_CONNECT_PORT[2] length[1-4] port[2] */
248 #define CD_CONNECT_PORT 2
251 * CD_LIST_NEIGH sends CDR_BINDATA if the command was successful. The response
255 * numfields[1-4] (field[2] fieldlen[1-4])[numfields]
256 * rows[responserows]:
257 * fieldlen[1-4], only if fieldlen in the header was "0"
258 * fielddata[fieldlen]
260 * Future versions may append data to field definition. Therefore clients must
261 * silently discard data at the end they do not expect.
264 /* list connected neighbors: CD_LIST_NEIGH[2] length[1-4] */
265 #define CD_LIST_NEIGH 3
270 #define LIST_NEIGH_FIELD_ADDR 1
273 * latency_in_microsecs[1] (64_11 encoding)
274 * Only raw network latency in measured. Delays caused by the priority queues
275 * are *not* included.
277 #define LIST_NEIGH_FIELD_LATENCY 2
279 /* list services: CD_LIST_SERVICES[2] length[1-4] */
280 #define CD_LIST_SERVICES 4
284 * Connection data response
285 * Format is the same as with connection data
294 * CDR_EXECFAILED[1] reasoncode[2]
296 #define CDR_EXECFAILED 2
297 #define CDR_EXECFAILED_INVALID_COMMAND 1
298 #define CDR_EXECFAILED_TEMPORARILY_OUT_OF_RESSOURCES 2
299 #define CDR_EXECFAILED_NB_DOESNTEXIST 3
300 #define CDR_EXECFAILED_PORTCLOSED 4
303 * must be sent after CDR_EXEC{OK|FAILED}
304 * CDR_EXEOK_BINDATA[1] bindatalen[1-4] bindata[bindatalen] */
305 #define CDR_BINDATA 3
308 * routing daemon sock
310 * cmdcode[4] length[4] cmddata[length]
314 #define CRD_KTU_SUPPORTEDVERSIONS 1
316 * CRD_KTU_SUPPORTEDVERSIONS[4] length[4] min[4] max[4]
319 #define CRD_KTU_CONNECT 2
321 * CRD_KTU_KTOU_CONNECT[4] length[4] cookie[8] targetlen[4] target[targetlen]
324 #define CRD_UTK_VERSION 1
326 * CRD_UTK_VERSION[4] length[4] version[4]
332 * CRD_UTK_UP[4] length[4] flags[8] addrlen[4] addr[addrlen]
337 #define CRD_UTK_CONNECTERROR 3
339 * CRD_UTK_CONNECTERROR[4] length[4] cookie[8] error[4]
342 #define CRD_UTK_CONNECTERROR_ACCES 1
343 #define CRD_UTK_CONNECTERROR_NETUNREACH 2
344 #define CRD_UTK_CONNECTERROR_TIMEDOUT 3
345 #define CRD_UTK_CONNECTERROR_REFUSED 4
347 #define CONN_MNGD_HEADERLEN 2
348 #define CONN_MNGD_CHECKSUMLEN 4
350 #define CONN_MNGD_HASDATA (1 << 15)
351 #define CONN_MNGD_EOF (1 << 0)
352 #define CONN_MNGD_RCVEND (1 << 1)
353 #define CONN_MNGD_DATALEN 4095
355 #define CONN_MNGD_MAX_SEGMENT_SIZE (CONN_MNGD_DATALEN + 1)
357 #define PRIORITY_MAX 15384774
362 /* result codes for rcv.c/proc_packet */
364 #define RC_FINISHED 1
366 #define RC_RCV1_ANNOUNCE 2
367 #define RC_RCV1_KERNEL 3
368 #define RC_RCV1_CONN 4
376 struct list_head queue_list
;
378 struct net_device
*dev
; /* may not change while queue is in list */
380 struct timer_list qos_resume_timer
;
381 struct tasklet_struct qos_resume_task
;
382 int qos_resume_scheduled
;
383 unsigned long jiffies_lastprogress
;
385 struct list_head kpackets_waiting
;
386 struct list_head conn_retrans_waiting
;
387 struct list_head announce_waiting
;
388 struct list_head neighbors_waiting
;
396 * switch to and from RB_INQUEUE_NBCONGWIN is only done with nbcongwin.lock
399 #define RB_INQUEUE_FALSE 0
400 #define RB_INQUEUE_TRUE 1
401 #define RB_INQUEUE_NBCONGWIN 2 /* only for nb->rb */
408 #define ANNOUNCE_TYPE_BROADCAST 1
409 #define ANNOUNCE_TYPE_UNICAST 2
411 struct announce_data
{
417 struct net_device
*dev
;
418 char mac
[MAX_ADDR_LEN
];
419 struct delayed_work announce_work
;
420 struct resume_block rb
;
424 ktime_t time_created
;
426 unsigned long jiffies_sent
;
429 __u8 pongs
; /* count of pongs for pings sent after this one */
432 #define NEIGHBOR_STATE_INITIAL 0
433 #define NEIGHBOR_STATE_ACTIVE 1
434 #define NEIGHBOR_STATE_STALLED 2
435 #define NEIGHBOR_STATE_KILLED 3
437 #define NBCONGWIN_SHIFT 16
438 #define NBCONGWIN_MUL (1 << NBCONGWIN_SHIFT)
441 struct list_head nb_list
;
445 struct net_device
*dev
;
446 char mac
[MAX_ADDR_LEN
];
447 struct qos_queue
*queue
;
451 atomic_t sessionid_rcv_needed
;
452 atomic_t sessionid_snd_needed
;
457 struct timer_list cmsg_timer
;
458 struct tasklet_struct cmsg_task
;
459 atomic_t cmsg_task_scheduled
;
460 atomic_t cmsg_timer_running
;
461 spinlock_t cmsg_lock
;
462 spinlock_t send_cmsg_lock
;
463 struct list_head cmsg_queue_pong
;
464 struct list_head cmsg_queue_ack
;
465 struct list_head cmsg_queue_ackconn
;
466 struct list_head cmsg_queue_conndata
;
467 struct list_head cmsg_queue_other
;
469 struct rb_root pending_conn_resets_rb
;
471 unsigned long timeout
;
473 __u32 cmsg_pongslength
;
474 __u32 cmsg_otherlength
;
476 __u32 cmsg_pongscnt
; /* size of queue only, protected by cmsg_lock */
477 atomic_t cmsg_pongs_retrans_cnt
; /* number of retransmits only */
478 atomic_t cmsg_othercnt
; /* size of queue + retransmits */
480 atomic_t cmsg_bulk_readds
;
483 unsigned long jiffies_last_cmsg
;
484 __u32 cmsg_interval
; /* microsecs */
486 __u8 max_cmsg_delay_sent
;
488 /* procected by qos_queue->qlock */
489 struct resume_block rb_kp
;
490 struct resume_block rb_cr
;
491 struct resume_block rb
;
496 struct list_head lh_nextpass
;
503 atomic64_t data_intransit
;
508 spinlock_t state_lock
;
509 unsigned long last_ping_time
;
511 struct ping_cookie cookies
[PING_COOKIES_PER_NEIGH
];
512 __u32 ping_intransit
;
515 __u64 latency_variance_retrans_us
; /* microsecs */
516 atomic_t latency_retrans_us
; /* microsecs */
517 atomic_t latency_stddev_retrans_us
; /* microsecs */
518 atomic_t latency_advertised_us
; /* microsecs */
519 atomic_t max_remote_ack_delay_us
; /* microsecs */
520 atomic_t max_remote_ackconn_delay_us
; /* microsecs */
521 atomic_t max_remote_other_delay_us
; /* microsecs */
524 unsigned long initial_state_since
;/* initial state */
527 * time of the last sent packet which has been acked or
528 * otherwise responded to (e.g. pong)
530 unsigned long last_roundtrip
;/* active/stalled state */
532 ktime_t last_roundtrip_end
;
536 __u8 str_timer_pending
;
537 struct delayed_work stalltimeout_timer
;
539 spinlock_t connid_lock
;
540 struct rb_root connid_rb
;
542 spinlock_t connid_reuse_lock
;
543 struct rb_root connid_reuse_rb
;
544 struct list_head connid_reuse_list
;
545 __u16 connid_reuse_pingcnt
;
547 spinlock_t kp_retransmits_lock
;
548 struct rb_root kp_retransmits_rb
;
552 atomic64_t priority_sum
;
555 * connecions which receive data from/send data to this node
556 * used when terminating all connections of a neighbor and terminating
557 * inactive connections
559 spinlock_t conn_list_lock
;
560 struct list_head rcv_conn_list
;
562 spinlock_t stalledconn_lock
;
563 struct work_struct stalledconn_work
;
564 __u8 stalledconn_work_scheduled
;
565 struct list_head stalledconn_list
;
568 * the timer has to be inited when adding the neighbor
570 * add_timer(struct timer_list * timer);
572 spinlock_t retrans_lock
;
573 struct timer_list retrans_timer
;
574 struct tasklet_struct retrans_task
;
575 __u8 retrans_timer_running
;
576 struct list_head retrans_list
;
578 spinlock_t retrans_conn_lock
;
579 struct timer_list retrans_conn_timer
;
580 struct tasklet_struct retrans_conn_task
;
581 struct list_head retrans_conn_list
;
582 __u8 retrans_conn_timer_running
;
583 __u8 retrans_conn_running
;
586 #define DATABUF_BUF 0
587 #define DATABUF_SKB 1
589 struct data_buf_item
{
590 struct list_head buf_list
;
599 struct connid_reuse_item
{
609 #define SNDSPEED_INIT 0
610 #define SNDSPEED_ACTIVE 1
614 unsigned long jiffies_last_refresh
;
617 /* bytes per second */
625 * There are 2 conn objects per bi-directional connection. They refer to each
626 * other with in the reversedir field.
632 * cn: conn we have no clue what is inside
633 * src_in, trgt_unconn, trgt_out, ...: A conn with the specified source or
634 * targettype. In the unlocked case the types are actually just a guess,
635 * because they could have changed since the last access. After locking the
636 * source/destination parameters have to be checked whether they still are
637 * what we expect. This includes source/targettype, neighbor, conn_id
639 * Exception: they may not change after they are set to source/target sock
640 * until the socket is released.
644 * no suffix: unlocked
646 * _l: this direction is locked
648 * _ll: both directions are locked
650 * _lx: this direction is locked, the other direction may be locked
652 * _o: unlocked, but source or target is known for sure, because an outside
653 * lock is taken; For variables on the heap this means that an outside lock must
654 * be taken before accessing the struct which points to the conn can be
660 * The following fields are immutable after the conn has been allocated:
661 * is_client, reversedir
663 * Most fields are protected by rcv_lock. Fields which which control
664 * source and destination of the data flow require both directions to
665 * to be locked and external references to be cleared before the change can
666 * happen. This includes fields like sourcetype, targettype, connid,
667 * list_heads, htab_entries, ???. In this case the side with is_client == 1
668 * needs to be locked first. Changes to conn_id and neighbor also require
669 * removing the conn from the htables first.
671 * Some other fields are locked outside (e.g. at struct neighbor).
673 #define SOURCE_UNCONNECTED 0
675 #define SOURCE_SOCK 2
677 #define TARGET_UNCONNECTED 0
679 #define TARGET_SOCK 2
680 #define TARGET_DISCARD 3
682 #define BUFSIZE_NOACTION 0
683 #define BUFSIZE_DECR 1
684 #define BUFSIZE_DECR_FAST 2
685 #define BUFSIZE_INCR 3
686 #define BUFSIZE_INCR_FAST 4
688 #define BUFSIZE_SHIFT 5
690 #define SOCKTYPE_RAW 0
691 #define SOCKTYPE_MANAGED 1
693 #define RCV_BUF_STATE_OK 0
694 #define RCV_BUF_STATE_INCOMPLETE 1
695 #define RCV_BUF_STATE_RESET 2
706 * 0... connection active
707 * 1... connection is about to be reset, target does not need to be
709 * 2... connection is reset
710 * 3... connection is reset + no pointers to "struct conn *reversedir"
711 * remaining except from this conn
724 /* list of all connections from this neighbor */
725 struct list_head nb_list
;
727 struct list_head reorder_queue
;
728 __u32 reorder_memused
;
731 struct connid_reuse_item
*cir
;
735 /* number of ack sent, not data seqno */
738 __u16 small_ooo_packets
;
742 __u8 inorder_ack_needed
;
746 __u64 window_seqnolimit
;
747 __u64 window_seqnolimit_remote
;
749 /* protected by nb->cmsg_lock */
750 struct list_head acks_pending
;
752 unsigned long jiffies_last_act
;
758 struct list_head cl_list
;
762 struct snd_speed snd_speed
;
773 char paramlen_buf
[4];
778 /* protected by nb->retrans_conn_lock, sorted by seqno
780 struct list_head retrans_list
;
782 /* protected by nb->stalledconn_lock */
783 struct list_head nbstalled_lh
;
786 __u64 seqno_nextsend
;
788 __u64 seqno_windowlimit
;
790 struct resume_block rb
;
799 __u8 priority_send_allowed
;
801 __u8 windowlimit_reached
;
805 /* protected by nb->retrans_conn_lock */
806 __u16 retrans_lowwindow
;
810 __u8 waiting_for_userspace
;
811 unsigned long waiting_for_userspace_since
;
818 char rcv_hdr
[CONN_MNGD_HEADERLEN
];
819 char rcv_chksum
[CONN_MNGD_CHECKSUMLEN
];
828 struct list_head items
;
829 struct data_buf_item
*nextread
;
834 __u32 read_remaining
;
836 __u16 next_read_offset
;
839 __u32 bufspace_accounted
;
842 __u32 bufsize
; /* 32 ==> 1 byte, see BUFSIZE_SHIFT */
843 __u32 ignore_rcv_lowbuf
;
862 struct conn
*reversedir
;
865 #define CONN_RETRANS_INITIAL 0
866 #define CONN_RETRANS_SCHEDULED 1
867 #define CONN_RETRANS_LOWWINDOW 2
868 #define CONN_RETRANS_SENDING 3
869 #define CONN_RETRANS_ACKED 4
870 struct conn_retrans
{
871 /* timeout_list and conn_list share a single ref */
873 /* only in timeout_list if state == CONN_RETRANS_SCHEDULED */
874 struct list_head timeout_list
;
875 struct list_head conn_list
;
876 struct conn
*trgt_out_o
;
880 __u8 snd_delayed_lowbuf
;
882 unsigned long timeout
;
901 struct skb_procstate
{
904 struct work_struct work
;
917 struct data_buf_item dbi
;
922 #define CS_TYPE_UNCONNECTED 0
923 #define CS_TYPE_LISTENER 1
924 #define CS_TYPE_CONN_RAW 2
925 #define CS_TYPE_CONN_MANAGED 3
927 #define CS_CONNECTSTATE_UNCONNECTED 0
928 #define CS_CONNECTSTATE_CONNECTING 1
929 #define CS_CONNECTSTATE_CONNECTED 2
930 #define CS_CONNECTSTATE_ERROR 3
932 #define CS_SHUTDOWN_SHUTDOWN_RD (1 << 0)
933 #define CS_SHUTDOWN_SHUTDOWN_WR (1 << 1)
934 #define CS_SHUTDOWN_SENT_EOF (1 << 2)
935 #define CS_SHUTDOWN_SENT_RCVEND (1 << 3)
936 #define CS_SHUTDOWN_RCVD_EOF (1 << 4)
937 #define CS_SHUTDOWN_RCVD_RCVEND (1 << 5)
940 struct sock sk
; /* must be first */
945 /* type may not change once it is set to != CS_TYPE_UNCONNECTED */
949 __u8 publish_service
;
953 /* listener is protected by cor_bindnodes */
956 __u8 publish_service
;
959 struct list_head conn_queue
;
963 struct conn
*src_sock
;
964 struct conn
*trgt_sock
;
966 struct data_buf_item
*rcvitem
;
969 __u8 snd_delayed_lowbuf
;
971 struct cor_sock
*pass_on_close
;
975 struct cor_sockaddr remoteaddr
;
977 struct list_head rd_msgs
;
978 struct list_head crd_lh
;
989 __u8 snd_delayed_lowbuf
;
994 struct conn
*src_sock
;
995 struct conn
*trgt_sock
;
997 char snd_hdr
[CONN_MNGD_HEADERLEN
];
998 char snd_chksum
[CONN_MNGD_CHECKSUMLEN
];
1000 __u16 snd_segment_size
;
1001 __u16 snd_hdr_flags
;
1004 /* protected by cor_sock->lock */
1005 __u8 in_flushtoconn_oom_list
;
1006 /* protected by flushtoconn_oom_lock */
1007 struct list_head flushtoconn_oom_lh
;
1010 char rcv_hdr
[CONN_MNGD_HEADERLEN
];
1011 char rcv_chksum
[CONN_MNGD_CHECKSUMLEN
];
1013 __u16 rcv_hdr_flags
;
1015 __u16 rcvbuf_consumed
;
1020 struct work_struct readfromconn_work
;
1021 atomic_t readfromconn_work_scheduled
;
1023 atomic_t ready_to_read
;
1024 atomic_t ready_to_write
;
1025 atomic_t ready_to_accept
;
1031 extern atomic_t num_conns
;
1033 extern spinlock_t cor_bindnodes
;
1035 extern struct conn
*get_conn(struct neighbor
*nb
, __u32 conn_id
);
1037 extern void delete_connid_reuse_items(struct neighbor
*nb
);
1039 extern void connid_used_pingsuccess(struct neighbor
*nb
);
1041 extern void _set_last_act(struct conn
*src_in_l
);
1043 extern void free_conn(struct kref
*ref
);
1045 extern int conn_init_out(struct conn
*trgt_unconn_ll
, struct neighbor
*nb
,
1046 __u32 rcvd_connid
, int use_rcvd_connid
);
1048 extern void conn_init_sock_source(struct conn
*cn
);
1050 extern void conn_init_sock_target(struct conn
*cn
);
1052 extern __u32
list_services(char *buf
, __u32 buflen
);
1054 extern void set_publish_service(struct cor_sock
*cs
, __u8 value
);
1056 extern void close_port(struct cor_sock
*cs
);
1058 extern int open_port(struct cor_sock
*cs_l
, __be16 port
);
1060 extern int connect_port(struct conn
*trgt_unconn_ll
, __be16 port
);
1062 extern int connect_neigh(struct conn
*trgt_unconn_ll
, char *addr
,
1065 extern struct conn
* alloc_conn(gfp_t allocflags
);
1067 extern void reset_conn_locked(struct conn
*cn_ll
);
1069 extern void reset_conn(struct conn
*cn
);
1072 extern __u8
__attribute__((const)) enc_log_256_16(__u32 value
);
1074 extern __u32
__attribute__((const)) dec_log_256_16(__u8 value
);
1076 extern __u8
__attribute__((const)) enc_log_64_11(__u32 value
);
1078 extern __u32
__attribute__((const)) dec_log_64_11(__u8 value
);
1080 extern __u8
__attribute__((const)) enc_log_64_7(__u64 value
);
1082 extern __u64
__attribute__((const)) dec_log_64_7(__u8 value
);
1084 extern void kreffree_bug(struct kref
*ref
);
1086 extern int __init
cor_util_init(void);
1089 extern int newconn_checkpriority(struct neighbor
*nb
, __u8 priority
);
1091 extern __u32
refresh_conn_priority(struct conn
*cn
, int locked
);
1093 extern void set_conn_in_priority(struct neighbor
*nb
, __u32 conn_id
,
1094 struct conn
*src_in
, __u8 priority_seqno
, __u8 priority
);
1096 extern void connreset_priority(struct conn
*cn
);
1098 extern int __init
credits_init(void);
1101 extern void neighbor_free(struct kref
*ref
);
1103 extern int is_from_nb(struct sk_buff
*skb
, struct neighbor
*nb
);
1105 extern struct neighbor
*get_neigh_by_mac(struct sk_buff
*skb
);
1107 extern struct neighbor
*find_neigh(char *addr
, __u16 addrlen
);
1109 extern __u32
generate_neigh_list(char *buf
, __u32 buflen
);
1111 extern int get_neigh_state(struct neighbor
*nb
);
1113 extern void ping_resp(struct neighbor
*nb
, __u32 cookie
, __u32 respdelay
);
1115 extern __u32
add_ping_req(struct neighbor
*nb
, unsigned long *last_ping_time
,
1118 extern void ping_sent(struct neighbor
*nb
, __u32 cookie
);
1120 extern void unadd_ping_req(struct neighbor
*nb
, __u32 cookie
,
1121 unsigned long last_ping_time
, int congested
);
1123 #define TIMETOSENDPING_NO 0
1124 #define TIMETOSENDPING_YES 1
1125 #define TIMETOSENDPING_FORCE 2
1126 extern int time_to_send_ping(struct neighbor
*nb
);
1128 extern unsigned long get_next_ping_time(struct neighbor
*nb
);
1130 extern int force_ping(struct neighbor
*nb
);
1132 extern int rcv_announce(struct sk_buff
*skb
);
1134 extern int _send_announce(struct announce_data
*ann
, int fromqos
, int *sent
);
1136 extern void announce_data_free(struct kref
*ref
);
1138 extern void announce_send_stop(struct net_device
*dev
, char *mac
, int type
);
1140 extern void cor_neighbor_down(void);
1142 extern int cor_neighbor_up(char *addr2
, __u32 addrlen2
);
1144 extern int is_clientmode(void);
1146 extern int __init
cor_neighbor_init(void);
1149 extern void reset_ooo_queue(struct conn
*src_in_lx
);
1151 extern void drain_ooo_queue(struct conn
*src_in_l
);
1153 extern void conn_rcv(struct neighbor
*nb
, struct sk_buff
*skb
, char *data
, __u32 len
,
1154 __u32 conn_id
, __u64 seqno
, int rcv_delayed_lowbuf
, __u8 flush
);
1156 extern void cor_rcv_down(void);
1158 extern void cor_rcv_up(void);
1160 extern int __init
cor_rcv_init(void);
1162 /* kpacket_parse.c */
1163 extern void kernel_packet(struct neighbor
*nb
, struct sk_buff
*skb
,
1167 struct control_msg_out
;
1169 #define ACM_PRIORITY_LOW 1 /* oom recovery easy */
1170 #define ACM_PRIORITY_MED 2 /* oom may cause timeouts */
1171 #define ACM_PRIORITY_HIGH 3 /* cm acks - needed for freeing old cms */
1173 extern struct control_msg_out
*alloc_control_msg(struct neighbor
*nb
,
1176 extern void free_control_msg(struct control_msg_out
*cm
);
1178 extern void retransmit_taskfunc(unsigned long arg
);
1180 extern void retransmit_timerfunc(struct timer_list
*retrans_timer
);
1182 extern void kern_ack_rcvd(struct neighbor
*nb
, __u64 seqno
);
1184 extern int send_messages(struct neighbor
*nb
, int resume
, int *sent
);
1186 extern void controlmsg_taskfunc(unsigned long nb
);
1188 extern void controlmsg_timerfunc(struct timer_list
*cmsg_timer
);
1190 extern void schedule_controlmsg_timer(struct neighbor
*nb_cmsglocked
);
1192 extern void send_pong(struct neighbor
*nb
, __u32 cookie
);
1194 extern int send_reset_conn(struct neighbor
*nb
, __u32 conn_id
, int lowprio
);
1196 extern void send_ack(struct neighbor
*nb
, __u64 seqno
);
1198 extern void send_ack_conn_ifneeded(struct conn
*src_in_l
, __u64 seqno_ooo
,
1201 extern void send_priority(struct conn
*trgt_out_ll
, int force
,
1204 extern void free_ack_conns(struct conn
*src_in_lx
);
1206 extern void send_connect_success(struct control_msg_out
*cm
, __u32 conn_id
,
1207 struct conn
*src_in
);
1209 extern void send_connect_nb(struct control_msg_out
*cm
, __u32 conn_id
,
1210 __u64 seqno1
, __u64 seqno2
, struct conn
*src_in_ll
);
1212 extern void send_conndata(struct control_msg_out
*cm
, __u32 conn_id
,
1213 __u64 seqno
, char *data_orig
, char *data
, __u32 datalen
,
1214 __u8 snd_delayed_lowbuf
, __u8 flush
,
1215 struct conn_retrans
*cr
);
1217 extern int __init
cor_kgen_init(void);
1219 /* cpacket_parse.c */
1220 extern int encode_len(char *buf
, int buflen
, __u32 len
);
1222 extern void proc_cpacket(struct conn
*trgt_unconn
);
1224 extern int __init
cor_cpacket_init(void);
1227 #ifdef DEBUG_QOS_SLOWSEND
1228 extern int cor_dev_queue_xmit(struct sk_buff
*skb
, int caller
);
1230 static inline int cor_dev_queue_xmit(struct sk_buff
*skb
, int caller
)
1232 return dev_queue_xmit(skb
);
1236 extern void free_qos(struct kref
*ref
);
1238 #ifdef COR_NBCONGWIN
1239 extern void nbcongwin_data_acked(struct neighbor
*nb
, __u64 bytes_acked
);
1242 extern struct qos_queue
*get_queue(struct net_device
*dev
);
1244 extern int destroy_queue(struct net_device
*dev
);
1246 extern int create_queue(struct net_device
*dev
);
1248 #define QOS_RESUME_DONE 0
1249 #define QOS_RESUME_CONG 1
1250 #define QOS_RESUME_NEXTNEIGHBOR 2 /* resume_neighbors() internal */
1252 #define QOS_CALLER_KPACKET 0
1253 #define QOS_CALLER_CONN_RETRANS 1
1254 #define QOS_CALLER_ANNOUNCE 2
1255 #define QOS_CALLER_NEIGHBOR 3
1257 extern void qos_enqueue(struct qos_queue
*q
, struct resume_block
*rb
,
1260 extern void qos_remove_conn(struct conn
*trgt_out_l
);
1262 extern int may_send_announce(struct net_device
*dev
);
1264 extern struct sk_buff
*create_packet_cmsg(struct neighbor
*nb
, int size
,
1265 gfp_t alloc_flags
, __u64 seqno
);
1267 extern void reschedule_conn_retrans_timer(struct neighbor
*nb_retranslocked
);
1269 extern void cancel_all_conn_retrans(struct conn
*trgt_out_l
);
1271 extern void retransmit_conn_taskfunc(unsigned long nb
);
1273 extern void retransmit_conn_timerfunc(struct timer_list
*retrans_timer_conn
);
1275 extern void conn_ack_ooo_rcvd(struct neighbor
*nb
, __u32 conn_id
,
1276 struct conn
*trgt_out
, __u64 seqno_ooo
, __u32 length
,
1277 __u64
*bytes_acked
);
1279 extern void conn_ack_rcvd(struct neighbor
*nb
, __u32 conn_id
,
1280 struct conn
*trgt_out
, __u64 seqno
, int setwindow
, __u8 window
,
1281 __u64
*bytes_acked
);
1283 extern void schedule_retransmit_conn(struct conn_retrans
*cr
, int connlocked
,
1284 int nbretrans_locked
);
1286 /* RC_FLUSH_CONN_OUT_SENT | RC_FLUSH_CONN_OUT_{^SENT} */
1287 #define RC_FLUSH_CONN_OUT_OK 1
1288 #define RC_FLUSH_CONN_OUT_SENT_CONG 2 /* flush_out internal only */
1289 #define RC_FLUSH_CONN_OUT_NBNOTACTIVE 3
1290 #define RC_FLUSH_CONN_OUT_CONG 4
1291 #define RC_FLUSH_CONN_OUT_MAXSENT 5
1292 #define RC_FLUSH_CONN_OUT_OOM 6
1294 extern int flush_out(struct conn
*trgt_out_lx
, __u32
*sent
);
1296 extern void resume_nbstalled_conns(struct work_struct
*work
);
1298 extern int __init
cor_snd_init(void);
1301 extern struct kmem_cache
*data_buf_item_slab
;
1303 extern void databuf_init(struct conn
*cn_init
);
1305 extern void bufsize_init(struct conn
*cn_l
, __u32 bufsize
);
1307 extern int account_bufspace(struct conn
*cn_lx
);
1309 extern int cpacket_write_allowed(struct conn
*src_unconn_lx
);
1311 extern void update_windowlimit(struct conn
*src_in_lx
);
1313 extern void bufsize_read_to_sock(struct conn
*trgt_sock_lx
);
1315 extern void databuf_ackdiscard(struct conn
*cn_lx
);
1317 extern void reset_seqno(struct conn
*cn_l
, __u64 initseqno
);
1319 extern void databuf_pull(struct conn
*cn_lx
, char *dst
, __u32 len
);
1321 static inline __u32
databuf_trypull(struct conn
*cn_l
, char *dst
, __u32 len
)
1323 if (len
> cn_l
->data_buf
.read_remaining
)
1324 len
= cn_l
->data_buf
.read_remaining
;
1325 databuf_pull(cn_l
, dst
, len
);
1329 extern void databuf_unpull_dpi(struct conn
*trgt_sock
, struct cor_sock
*cs
,
1330 struct data_buf_item
*item
, __u16 next_read_offset
);
1332 extern void databuf_pull_dbi(struct cor_sock
*cs_rl
, struct conn
*trgt_sock_l
);
1334 extern void databuf_unpull(struct conn
*trgt_out_l
, __u32 bytes
);
1336 extern void databuf_pullold(struct conn
*trgt_out_l
, __u64 startpos
, char *dst
,
1339 extern void databuf_ack(struct conn
*trgt_out_l
, __u64 pos
);
1341 extern void databuf_ackread(struct conn
*cn_lx
);
1343 extern __u32
receive_buf(struct conn
*cn_lx
, char *buf
, __u32 datalen
,
1344 int rcv_delayed_lowbuf
, __u8 flush
);
1346 extern __u32
receive_skb(struct conn
*src_in_l
, struct sk_buff
*skb
,
1347 int rcv_delayed_lowbuf
, __u8 flush
);
1349 extern void wake_sender(struct conn
*cn
);
1351 extern int __init
forward_init(void);
1353 /* sock_rdaemon.c */
1354 extern int cor_create_rdaemon_sock(struct net
*net
, struct socket
*sock
,
1355 int protocol
, int kern
);
1357 extern int rdreq_connect(struct cor_sock
*cs
);
1359 extern void cor_usersock_release(struct cor_sock
*cs
);
1361 extern int __init
cor_rd_init1(void);
1363 extern int __init
cor_rd_init2(void);
1366 extern int cor_create_raw_sock(struct net
*net
, struct socket
*sock
,
1367 int protocol
, int kern
);
1369 /* sock_managed.c */
1370 extern struct cor_sock
*get_corsock_by_cookie(__be64 cookie
);
1372 extern void __set_sock_connecterror(struct cor_sock
*cs_m_l
, int errorno
);
1374 extern void _set_sock_connecterror(struct cor_sock
*cs
, int errorno
);
1376 static inline void set_sock_connecterror(__be64 cookie
, int errorno
)
1378 struct cor_sock
*cs
= get_corsock_by_cookie(cookie
);
1379 _set_sock_connecterror(cs
, errorno
);
1382 extern void flush_sock_managed(struct conn
*trgt_sock_lx
, int from_recvmsg
,
1383 __u8
*do_wake_sender
);
1385 extern void cor_mngdsocket_readfromconn_fromatomic(struct cor_sock
*cs
);
1387 extern void cor_mngdsocket_readfromconn_wq(struct work_struct
*work
);
1389 extern int cor_create_managed_sock(struct net
*net
, struct socket
*sock
,
1390 int protocol
, int kern
);
1392 extern int __init
cor_sock_managed_init1(void);
1395 extern void free_sock(struct kref
*ref
);
1397 extern void flush_sock(struct conn
*trgt_sock_lx
);
1399 extern void update_src_sock_sndspeed(struct conn
*src_sock_l
, __u32 bytes_sent
);
1401 extern int cor_sock_sndbufavailable(struct conn
*src_sock_lx
);
1403 extern int cor_socket_socketpair(struct socket
*sock1
, struct socket
*sock2
);
1405 extern int cor_socket_getname(struct socket
*sock
, struct sockaddr
*addr
,
1408 extern int cor_socket_mmap(struct file
*file
, struct socket
*sock
,
1409 struct vm_area_struct
*vma
);
1411 extern int _cor_createsock(struct net
*net
, struct socket
*sock
, int protocol
,
1414 extern int __init
cor_sock_init1(void);
1416 extern int __init
cor_sock_init2(void);
1419 static inline struct skb_procstate
*skb_pstate(struct sk_buff
*skb
)
1421 return (struct skb_procstate
*) &(skb
->cb
[0]);
1424 static inline struct sk_buff
*skb_from_pstate(struct skb_procstate
*ps
)
1426 return (struct sk_buff
*) (((char *)ps
) - offsetof(struct sk_buff
,cb
));
1429 static inline __u32
mss(struct neighbor
*nb
, __u32 l3overhead
)
1431 __u32 mtu
= (nb
->dev
->mtu
> 4096) ? 4096 : nb
->dev
->mtu
;
1432 return mtu
- LL_RESERVED_SPACE(nb
->dev
) - l3overhead
;
1435 static inline __u32
mss_cmsg(struct neighbor
*nb
)
1440 static inline __u32
mss_conndata(struct neighbor
*nb
)
1442 __u32 mss_tmp
= mss(nb
, 11);
1448 for (i
=256;i
<4096;i
*=2) {
1453 return mss_tmp
- mss_tmp
%4096;
1456 static inline __u32
send_conndata_as_skb(struct neighbor
*nb
, __u32 size
)
1458 return size
>= mss_conndata(nb
)/2;
1461 static inline long calc_timeout(__u32 latency_us
, __u32 latency_stddev_us
,
1462 __u32 max_remote_ack_delay_us
)
1464 unsigned long addto
;
1465 if (unlikely(unlikely(latency_us
> 1000000000) ||
1466 unlikely(latency_stddev_us
> 500000000) ||
1467 unlikely(max_remote_ack_delay_us
> 1000000000))) {
1468 addto
= msecs_to_jiffies(latency_us
/1000 + latency_us
/4000 +
1469 latency_stddev_us
/333 +
1470 max_remote_ack_delay_us
/1000);
1472 addto
= usecs_to_jiffies(latency_us
+ latency_us
/4 +
1473 latency_stddev_us
*3 + max_remote_ack_delay_us
);
1477 * 2 is added because
1478 * 1) _to_jiffies rounds down, but should round up, so add 1 to
1480 * 2) even if latency is 0, we never want to schedule the retransmit
1481 * to run right now, so add 1 more
1483 return jiffies
+ 2 + addto
;
1486 static inline void put_be64(char *dst
, __be64 value
)
1488 char *p_value
= (char *) &value
;
1490 dst
[0] = p_value
[0];
1491 dst
[1] = p_value
[1];
1492 dst
[2] = p_value
[2];
1493 dst
[3] = p_value
[3];
1494 dst
[4] = p_value
[4];
1495 dst
[5] = p_value
[5];
1496 dst
[6] = p_value
[6];
1497 dst
[7] = p_value
[7];
1500 static inline void put_u64(char *dst
, __u64 value
)
1502 put_be64(dst
, cpu_to_be64(value
));
1505 static inline void put_u48(char *dst
, __u64 value
)
1507 char *p_value
= (char *) &value
;
1509 value
= cpu_to_be64(value
);
1511 dst
[0] = p_value
[2];
1512 dst
[1] = p_value
[3];
1513 dst
[2] = p_value
[4];
1514 dst
[3] = p_value
[5];
1515 dst
[4] = p_value
[6];
1516 dst
[5] = p_value
[7];
1519 static inline void put_be32(char *dst
, __be32 value
)
1521 char *p_value
= (char *) &value
;
1522 dst
[0] = p_value
[0];
1523 dst
[1] = p_value
[1];
1524 dst
[2] = p_value
[2];
1525 dst
[3] = p_value
[3];
1528 static inline void put_u32(char *dst
, __u32 value
)
1530 put_be32(dst
, cpu_to_be32(value
));
1533 static inline void put_be16(char *dst
, __be16 value
)
1535 char *p_value
= (char *) &value
;
1536 dst
[0] = p_value
[0];
1537 dst
[1] = p_value
[1];
1540 static inline void put_u16(char *dst
, __u16 value
)
1542 put_be16(dst
, cpu_to_be16(value
));
1545 static inline char *cor_pull_skb(struct sk_buff
*skb
, unsigned int len
)
1547 char *ptr
= skb_pull(skb
, len
);
1549 if (unlikely(ptr
== 0))
1555 static inline __be64
parse_be64(char *buf
)
1561 ((char *)&ret
)[0] = buf
[0];
1562 ((char *)&ret
)[1] = buf
[1];
1563 ((char *)&ret
)[2] = buf
[2];
1564 ((char *)&ret
)[3] = buf
[3];
1565 ((char *)&ret
)[4] = buf
[4];
1566 ((char *)&ret
)[5] = buf
[5];
1567 ((char *)&ret
)[6] = buf
[6];
1568 ((char *)&ret
)[7] = buf
[7];
1573 static inline __u64
parse_u64(char *buf
)
1575 return be64_to_cpu(parse_be64(buf
));
1578 static inline __u64
parse_u48(char *ptr
)
1582 ((char *)&ret
)[0] = 0;
1583 ((char *)&ret
)[1] = 0;
1584 ((char *)&ret
)[2] = ptr
[0];
1585 ((char *)&ret
)[3] = ptr
[1];
1586 ((char *)&ret
)[4] = ptr
[2];
1587 ((char *)&ret
)[5] = ptr
[3];
1588 ((char *)&ret
)[6] = ptr
[4];
1589 ((char *)&ret
)[7] = ptr
[5];
1591 return be64_to_cpu(ret
);
1594 static inline __be32
parse_be32(char *ptr
)
1600 ((char *)&ret
)[0] = ptr
[0];
1601 ((char *)&ret
)[1] = ptr
[1];
1602 ((char *)&ret
)[2] = ptr
[2];
1603 ((char *)&ret
)[3] = ptr
[3];
1608 static inline __u32
parse_u32(char *ptr
)
1610 return be32_to_cpu(parse_be32(ptr
));
1613 static inline __be16
parse_be16(char *ptr
)
1619 ((char *)&ret
)[0] = ptr
[0];
1620 ((char *)&ret
)[1] = ptr
[1];
1625 static inline __u16
parse_u16(char *ptr
)
1627 return be16_to_cpu(parse_be16(ptr
));
1630 static inline __u64
pull_u48(struct sk_buff
*skb
)
1632 return parse_u48(cor_pull_skb(skb
, 6));
1635 static inline __be32
pull_be32(struct sk_buff
*skb
)
1637 return parse_be32(cor_pull_skb(skb
, 4));
1640 static inline __u32
pull_u32(struct sk_buff
*skb
)
1642 return parse_u32(cor_pull_skb(skb
, 4));
1645 static inline __u16
pull_u16(struct sk_buff
*skb
)
1647 return parse_u16(cor_pull_skb(skb
, 2));
1650 static inline __u8
pull_u8(struct sk_buff
*skb
)
1652 char *ptr
= cor_pull_skb(skb
, 1);
1657 static inline int is_conn_in(struct conn
*cn_l
, struct neighbor
*nb
,
1660 if (unlikely(unlikely(cn_l
->sourcetype
!= SOURCE_IN
) ||
1661 unlikely(cn_l
->source
.in
.nb
!= nb
) ||
1662 unlikely(cn_l
->source
.in
.conn_id
!= conn_id
) ||
1663 unlikely(cn_l
->isreset
!= 0)))
1668 static inline int is_src_sock(struct conn
*cn_l
, struct cor_sock
*cs
)
1670 if (unlikely(unlikely(cn_l
->sourcetype
!= SOURCE_SOCK
) ||
1671 unlikely(cn_l
->source
.sock
.cs
!= cs
)))
1676 static inline int is_trgt_sock(struct conn
*cn_l
, struct cor_sock
*cs
)
1678 if (unlikely(unlikely(cn_l
->targettype
!= TARGET_SOCK
) ||
1679 unlikely(cn_l
->target
.sock
.cs
!= cs
)))
1684 static inline void set_last_act(struct conn
*src_in_l
)
1686 unsigned long jiffies_tmp
= jiffies
;
1688 BUG_ON(src_in_l
->sourcetype
!= SOURCE_IN
);
1690 if (unlikely(time_after(jiffies_tmp
,
1691 src_in_l
->source
.in
.jiffies_last_act
+
1692 HZ
* CONN_ACTIVITY_UPDATEINTERVAL_SEC
)))
1693 _set_last_act(src_in_l
);
1696 #define BUFLEN_MIN 128
1697 #define BUFLEN_MAX 4096
1698 #define PAGESIZE (1 << PAGE_SHIFT)
1700 static inline __u32
buf_optlen(__u32 datalen
)
1702 __u32 optlen
= BUFLEN_MIN
;
1703 while (optlen
< datalen
&& optlen
< PAGESIZE
&& optlen
< BUFLEN_MAX
)
1704 optlen
= (optlen
<< 1);
1709 inline static void databuf_item_free(struct data_buf_item
*item
)
1711 if (item
->type
== DATABUF_BUF
) {
1713 kmem_cache_free(data_buf_item_slab
, item
);
1714 } else if (item
->type
== DATABUF_SKB
) {
1715 struct sk_buff
*skb
= skb_from_pstate(container_of(item
,
1716 struct skb_procstate
, funcstate
.rcv
.dbi
));
1723 static inline __u64
seqno_clean(__u64 seqno
)
1725 return seqno
& ((1LL << 48) - 1);
1728 static inline int seqno_eq(__u64 seqno1
, __u64 seqno2
)
1730 seqno1
= seqno1
<< 16;
1731 seqno2
= seqno2
<< 16;
1732 return seqno1
== seqno2
;
1735 static inline int seqno_before(__u64 seqno1
, __u64 seqno2
)
1737 seqno1
= seqno1
<< 16;
1738 seqno2
= seqno2
<< 16;
1739 return (seqno1
- seqno2
) >= (1LL << 63);
1742 static inline int seqno_before_eq(__u64 seqno1
, __u64 seqno2
)
1744 return seqno_eq(seqno1
, seqno2
) || seqno_before(seqno1
, seqno2
);
1747 static inline int seqno_after(__u64 seqno1
, __u64 seqno2
)
1749 return seqno_before_eq(seqno1
, seqno2
) ? 0 : 1;
1752 static inline int seqno_after_eq(__u64 seqno1
, __u64 seqno2
)
1754 return seqno_before(seqno1
, seqno2
) ? 0 : 1;
1757 static inline int ktime_before_eq(ktime_t time1
, ktime_t time2
)
1759 return ktime_after(time1
, time2
) ? 0 : 1;
1762 static inline int ktime_after_eq(ktime_t time1
, ktime_t time2
)
1764 return ktime_before(time1
, time2
) ? 0 : 1;
1767 static inline __u64
update_atomic_sum(atomic64_t
*atomic_sum
, __u32 oldvalue
,
1770 __u64 sum_old
= atomic64_read(atomic_sum
);
1778 BUG_ON(sum
< oldvalue
);
1781 BUG_ON(sum
+ newvalue
< sum
);
1784 cmpxchg_ret
= atomic64_cmpxchg(atomic_sum
, sum_old
, sum
);
1786 if (likely(cmpxchg_ret
== sum_old
))
1789 sum_old
= cmpxchg_ret
;
1795 static inline void cor_sk_write_space(struct cor_sock
*cs
)
1797 atomic_set(&(cs
->ready_to_write
), 1);
1799 cs
->sk
.sk_write_space(&(cs
->sk
));
1802 static inline void cor_sk_data_ready(struct cor_sock
*cs
)
1804 atomic_set(&(cs
->ready_to_read
), 1);
1806 cs
->sk
.sk_data_ready(&(cs
->sk
));
1809 /* the other direction may be locked only if called from proc_cpacket */
1810 static inline void flush_buf(struct conn
*cn_lx
)
1812 if (unlikely(cn_lx
->targettype
== TARGET_UNCONNECTED
)) {
1813 proc_cpacket(cn_lx
);
1814 } else if (cn_lx
->targettype
== TARGET_SOCK
) {
1816 } else if (cn_lx
->targettype
== TARGET_OUT
) {
1817 __u32 bytessent
= 0;
1818 flush_out(cn_lx
, &bytessent
);
1819 } else if (unlikely(cn_lx
->targettype
== TARGET_DISCARD
)) {
1820 databuf_ackdiscard(cn_lx
);