double send_reset race, free_ack_conns on reset, lock both conn sides on reset, skip...
[cor_2_6_31.git] / net / cor / cor.h
blobe045f245cabdd30f328eac9d39cafc3ca41b2180
1 /**
2 * Connection oriented routing
3 * Copyright (C) 2007-2011 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
18 * 02110-1301, USA.
21 #include <asm/atomic.h>
23 #include <linux/types.h>
24 #include <linux/netdevice.h>
25 #include <linux/skbuff.h>
26 #include <linux/spinlock.h>
27 #include <linux/workqueue.h>
28 #include <linux/kref.h>
29 #include <linux/ktime.h>
31 #include "settings.h"
34 #define S64_MAX 9223372036854775807LL
35 #define S64_MIN (1LL << 63)
38 #define ETH_P_COR 0x1022
39 #define AF_COR 37
40 #define PF_COR AF_COR
42 #define SOCKADDRTYPE_PORT 1
43 struct cor_sockaddr {
44 int type;
46 union {
47 __be64 port;
48 } addr;
51 #define MAX_CONN_CMD_LEN 4096
54 #define PACKET_TYPE_ANNOUNCE 1
55 #define PACKET_TYPE_DATA 2
58 * Kernel packet data - these commands are sent by the neighbor
59 * The end nodes may cause these commands to be sent, but they see them beyond
60 * the first hop.
63 /* KP_PADDING[1] */
64 #define KP_PADDING 1
67 * KP_PING[1] cookie[4]
68 * KP_PONG[1] cookie[4] respdelay[4]
70 * This is needed to find out whether the other node is reachable. After a new
71 * neighbor is seen, ping requests are sent and the neighbor is only reachable
72 * after a few pongs are received. These requests are also used to find out
73 * whether a neighber is gone.
75 * respdelay:
76 * The receiver of a ping may delay the sending of the pong e.g. to create
77 * bigger kernel packets. The respdelay is the time in microseconds the packet
78 * was delayed.
80 #define KP_PING 2
81 #define KP_PONG 3
83 /* KP_ACK[1] seqno[4] */
84 #define KP_ACK 4
87 * KP_ACK_CONN[1] conn_id[4] flags[1] seqno[4] window[1] seqno_ooo[4]
88 * length[1-4] credits[2]
90 * conn_id is the conn_id we use if we sent something through this conn and
91 * *not* the conn_id that the neighbor used to send us the data
93 * flags defines which of the following fields are sent
95 * seqno = the seqno which is expected in the next non-out-of-order packet
97 * window = amount of data which can be sent without receiving the next ack
98 * packets with lower seqno do not overwrite the last window size
99 * note: the other side may also reduce the window size
100 * decode:
101 * 0 = 0
102 * 1...255 = 64*2^((value-1)/11) end result is rounded down to an integer
104 * todo 32* 2 ^ ((value-1)/8)
106 * seqno_ooo, length = This packet was received out of order. Maybe a previous
107 * packet has been lost. Out of order data should not be retransmitted.
108 * Multiple ooo packets may be merged into a single ack. Ooo packets may be
109 * partially accepted, so that the length does not cover the full packet and/
110 * or the seqno starts in the middle of a packet
112 * credits = decaytime+seqno
114 #define KP_ACK_CONN 5
116 #define KP_ACK_CONN_FLAGS_SEQNO 1
117 #define KP_ACK_CONN_FLAGS_WINDOW 2
118 #define KP_ACK_CONN_FLAGS_OOO 12 /* 4+8 */
119 #define KP_ACK_CONN_FLAGS_CREDITS 16
121 static inline __u8 ooolen_to_flags(__u32 len)
123 if (len == 0)
124 return 0;
125 if (len < 256)
126 return 4;
127 if (len < 65536)
128 return 8;
129 return 12;
132 static inline int ooolen(__u8 flags)
134 int len = ((flags & KP_ACK_CONN_FLAGS_OOO) >> 2);
135 if (unlikely(len == 3))
136 return 4;
137 return len;
140 static inline int ack_conn_len(__u8 flags)
142 int len = 0;
143 if ((flags & KP_ACK_CONN_FLAGS_SEQNO) != 0) {
144 len += 4;
145 if ((flags & KP_ACK_CONN_FLAGS_WINDOW) != 0)
146 len++;
149 if (ooolen(flags) != 0) {
150 len += 4;
151 len += ooolen(flags);
154 if (flags & KP_ACK_CONN_FLAGS_CREDITS)
155 len += 2;
157 return len;
161 * NOTE on connection ids:
162 * connection ids + init seqnos we send are used for the receive channel
163 * connection ids + init seqnos we receive are used for the send channel
165 * ATTENTION: the credit seqno are reversed:
166 * decaytime seqnos we send are used when we send updates
167 * decaytime seqnos we received are used when we receive updates
171 * incoming connection
172 * credits = decaytime+seqno
173 * KP_CONNECT[1] conn_id[4] init_seqno[4] window[1] credits[2]
175 #define KP_CONNECT 6
178 * incoming connection successful,
179 * the first conn_id is the same as previously sent/received in KP_CONNECT
180 * the second conn_id is generated by us and used for the other direction
181 * KP_CONNECT_SUCCESS[1] conn_id[4] conn_id[4] init_seqno[4] window[1]
182 * credits[2]
184 #define KP_CONNECT_SUCCESS 7
186 /* KP_CONN_DATA[1] conn_id[4] seqno[4] length[2] data[length] */
187 #define KP_CONN_DATA 8
190 * { KP_RESET_CONN[1] conn_id[4] }
191 * We send this, if there is an established connection we want to close.
193 #define KP_RESET_CONN 9
196 * KP_CONNID_UNKNOWN[1] sent_conn_id[4]
197 * We send this, if we receive an invalid conn_id
199 #define KP_CONNID_UNKNOWN 10
202 * KP_SET_MAX_CMSG_DELAY[1] delay[4]
203 * Sent after connecting and at any change
204 * delay in specifies in microsecs
206 #define KP_SET_MAX_CMSG_DELAY 11
210 * Connection data which in interpreted when connection has no target yet
211 * These commands are sent by the end node.
213 * Format:
214 * cmd[2] length[1-4] parameter[length]
215 * unrecogniced commands are ignored
216 * parameters which are longer than expected are ignored as well
219 /* outgoing connection: CD_CONNECT_NB[2] length[1-4]
220 * addrtypelen[1-4] addrlen[1-4] addrtype[addrtypelen] addr[addrlen] */
221 #define CD_CONNECT_NB 1
223 /* connection to local open part: CD_CONNECT_PORT[2] length[1-4] port[8] */
224 #define CD_CONNECT_PORT 2
227 * CD_LIST_NEIGH sends CDR_BINDATA if the command was successful. The response
228 * format is:
230 * totalneighs[1-4] response_rows[1-4]
231 * numfields[1-4] (field[2] fieldlen[1-4])[numfields]
232 * rows[responserows]:
233 * fieldlen[1-4], only if fieldlen in the header was "0"
234 * fielddata[fieldlen]
236 * Neighbors have to be sorted by uptime, new neighbors first. This is so that
237 * the routing daemon can easily find out whether there are new neighbors. It
238 * only needs to send a query with offset 0. If the totalneighs stays the same
239 * while new were added, a connection to another neighbor was lost.
241 * Future versions may append data to field definition. Therefore clients must
242 * silently discard data at the end they do not expect.
245 /* list connected neighbors: CD_LIST_NEIGH[2] length[1-4] limit[1-4]
246 * offset[1-4] */
247 #define CD_LIST_NEIGH 3
250 * numaddr[1-4] (addrtypelen[1-4] addrlen[1-4] addrtype[addrtypelen]
251 * addr[addrlen])[numaddr]
253 #define LIST_NEIGH_FIELD_ADDR 1
256 * latency_in_microsecs[4]
257 * Only raw network latency in measured. Delays caused by the credit system are
258 * *not* included.
260 #define LIST_NEIGH_FIELD_LATENCY 2
264 * CD_SET_TOS[2] length[1-4] forward_tos[1] backward_tos[1]
265 * Only 2 bits of the tos flags are used, the highers 6 bits are ignored.
267 #define CD_SET_TOS 4
269 #define TOS_NORMAL 0
270 #define TOS_LATENCY 1
271 #define TOS_THROUGHPUT 2
272 #define TOS_PRIVACY 3
277 * Connection data response
278 * Format is the same as with connection data
282 * CDR_EXECOK[1]
284 #define CDR_EXECOK 1
287 * CDR_EXECFAILED[1] reasoncode[2]
288 * reasontextlength[1-4] reasontext[reasontextlength]
289 * reasontextlength may be 0
291 #define CDR_EXECFAILED 2
292 #define CDR_EXECFAILED_UNKNOWN_COMMAND 1
293 #define CDR_EXECFAILED_PERMISSION_DENIED 2
294 #define CDR_EXECFAILED_TEMPORARILY_OUT_OF_RESSOURCES 3
295 #define CDR_EXECFAILED_CMD_TOO_SHORT 4
296 #define CDR_EXECFAILED_CMD_TOO_LONG 5
297 #define CDR_EXECFAILED_TARGETADDRTYPE_UNKNOWN 6
298 #define CDR_EXECFAILED_TARGETADDR_DOESNTEXIST 7
299 #define CDR_EXECFAILED_TARGETADDR_PORTCLOSED 8
300 #define CDR_EXECFAILED_LISTENERQUEUE_FULL 9
301 #define CDR_EXECFAILED_ILLEGAL_COMMAND 10
304 * must be sent after CDR_EXEC{OK|FAILED}
305 * CDR_EXEOK_BINDATA[1] bindatalen[1-4] bindata[bindatalen] */
306 #define CDR_BINDATA 3
309 * sending 2^32 credits per millisec means that credits the neighbor owns
310 * should be halfed after 1 minute
312 * ((x - 4294967295)/x) ^ 60000 = 0.5
313 * (x-4294967295)/x = 0.5**(1/60000)
314 * x/x - 4294967295/x = 0.5**(1/60000)
315 * 1 - 0.5**(1/60000) = 4294967295/x
316 * x = 4294967295 / (1 - 0.5**(1/60000))
318 #define CREDITS_TOTAL (1LL << 63)
322 /* result codes for rcv.c/proc_packet */
323 #define RC_DROP 0
324 #define RC_FINISHED 1
326 #define RC_RCV1_ANNOUNCE 2
327 #define RC_RCV1_KERNEL 3
328 #define RC_RCV1_CONN 4
330 struct htab_entry{
331 /* start of next element, *not* next htab_entry */
332 void *next;
335 struct htable{
336 struct htab_entry **htable;
337 __u32 htable_size;
338 __u32 cell_size;
339 __u32 num_elements;
341 int (*matches)(void *htentry, void *searcheditem);
342 __u32 key_offset;
343 __u32 entry_offset;
344 __u32 kref_offset;
347 struct resume_block{
348 struct list_head lh;
349 int in_queue;
352 struct announce_data{
353 struct kref ref;
355 struct list_head lh;
356 struct net_device *dev;
357 struct delayed_work announce_work;
358 struct announce *ann;
359 struct resume_block rb;
361 __u32 curr_announce_msg_offset;
362 __u64 scheduled_announce_timer;
365 struct ping_cookie{
366 ktime_t time;
367 __u32 cookie;
368 __u8 pongs; /* count of pongs for pings sent after this one */
371 #define NEIGHBOR_STATE_INITIAL 0
372 #define NEIGHBOR_STATE_ACTIVE 1
373 #define NEIGHBOR_STATE_STALLED 2
374 #define NEIGHBOR_STATE_KILLED 3
376 struct neighbor{
377 struct list_head nb_list;
379 struct kref ref;
381 struct net_device *dev;
382 char mac[MAX_ADDR_LEN];
384 char *addr;
385 __u16 addrlen;
387 struct timer_list cmsg_timer;
388 struct work_struct cmsg_work;
389 atomic_t cmsg_work_scheduled;
390 atomic_t cmsg_timer_running;
391 struct mutex cmsg_lock;
392 struct mutex send_cmsg_lock;
393 struct list_head control_msgs_out;
395 * urgent messages; These are sent even if the neighbor state is not
396 * active. If the queue gets full, the oldest ones are dropped. It thus
397 * may only contain messages which are allowed to be dropped.
399 struct list_head ucontrol_msgs_out;
400 unsigned long timeout;
401 __u32 cmlength;
402 __u32 ucmlength;
404 atomic_t cmcnt; /* size of queue + retransmits */
405 atomic_t ucmcnt; /* size of queue only */
407 unsigned long jiffies_last_cmsg;
408 __u32 cmsg_interval; /* microsecs */
410 __u8 max_cmsg_delay_sent;
412 /* procected by queues_lock */
413 struct resume_block rb_kp;
414 struct resume_block rb_cr;
416 spinlock_t busytill_lock;
417 unsigned long busy_till;
419 struct mutex pingcookie_lock;
420 unsigned long last_ping_time;
421 __u32 ping_intransit;
422 struct ping_cookie cookies[PING_COOKIES_PER_NEIGH];
423 __u32 lastcookie;
424 atomic_t latency; /* microsecs */
425 atomic_t max_remote_cmsg_delay; /* microsecs */
427 spinlock_t state_lock;
428 union {
429 __u64 last_state_change;/* initial state */
431 * last_roundtrip:
432 * time of the last sent packet which has been acked or
433 * otherwise responded to (e.g. pong)
435 ktime_t last_roundtrip;/* active/stalled state */
436 }state_time;
437 __u8 state;
438 __u16 ping_success;
440 struct delayed_work stalltimeout_timer;
441 __u8 str_timer_pending;
444 atomic_t kpacket_seqno;
445 atomic_t ooo_packets;
447 spinlock_t credits_lock;
448 unsigned long jiffies_credit_update;
449 unsigned long jiffies_credit_decay;
451 /* we only keep track on how much the other side may spend */
452 __u64 credits;
453 __u32 credits_fract;
454 /* credit rates are in credits/sec */
455 __u32 creditrate_initial;
456 __u64 creditrate_earning;
457 __u64 creditrate_spending;
460 * connecions which receive data from/send data to this node
461 * used when terminating all connections of a neighbor
463 spinlock_t conn_list_lock;
464 struct list_head rcv_conn_list;
467 * the timer has to be inited when adding the neighbor
468 * init_timer(struct timer_list * timer);
469 * add_timer(struct timer_list * timer);
471 spinlock_t retrans_lock;
472 struct delayed_work retrans_timer_conn;
473 struct delayed_work retrans_timer;
474 __u8 retrans_timer_conn_running;
475 __u8 retrans_timer_running;
477 struct list_head retrans_list;
478 struct list_head retrans_list_conn;
480 struct conn *firstboundconn;
483 struct cor_sched_data{
484 spinlock_t lock;
485 struct list_head conn_list;
486 struct sk_buff_head requeue_queue;
489 #define TYPE_BUF 0
490 #define TYPE_SKB 1
492 struct data_buf_item{
493 struct list_head buf_list;
495 union {
496 struct {
497 char *buf;
498 __u16 datalen;
499 __u16 buflen;
501 }buf;
503 struct sk_buff *skb;
504 }data;
506 __u8 type;
509 struct connlistener;
511 struct bindnode{
512 struct list_head lh;
513 struct connlistener *owner;
514 __be64 port;
517 #define SOCKSTATE_LISTENER 1
518 #define SOCKSTATE_CONN 2
520 struct sock_hdr {
521 /* The first member of connlistener/conn (see sock.c) */
522 __u8 sockstate;
525 struct connlistener {
526 /* The first member has to be the same as in conn (see sock.c) */
527 __u8 sockstate;
528 struct bindnode *bn;
529 struct mutex lock;
530 int queue_maxlen;
531 int queue_len;
532 struct list_head conn_queue;
533 wait_queue_head_t wait;
537 struct speedtracker{
538 __u64 speed;/* bytes*65536/jiffie */
539 unsigned long jiffies_last_update;
540 __u32 bytes_curr;
544 * There are 2 conn objects per bi-directional connection. They refer to each
545 * other with in the reversedir field.
549 * Naming:
550 * cn: conn we have no clue what is inside
552 * src_in, trgt_unconn, trgt_out, ...: A conn with the specified source or
553 * targettype. In the unlocked case the types are actually just a guess,
554 * because they could have changed since the last access. After locking the
555 * source/destination parameters have to be checked whether they still are
556 * what we expect. This includes source/targettype, neighbor, conn_id,
559 * Naming suffixes:
560 * no suffix: unlocked
562 * _l: this direction is locked
564 * _ll: both directions are locked
566 * _lc: locked for credits: If source/targettype is in/out and connid is set on
567 * the target.out, only this direction is locked. Otherwise both directions are
568 * locked.
570 * _o: unlocked, but source or target is known for sure, because an outside
571 * lock is taken; For variables on the heap this means that an outside lock must
572 * be taken before accessing the struct which points to the conn can be
573 * accessed.
577 * Locking:
578 * The following fields are immutable after the conn has been allocated:
579 * is_client, reversedir
581 * Most fields are protected by rcv_lock. Fields which which control
582 * source and destination of the data flow require both directions to
583 * to be locked and external references to be cleared before the change can
584 * happen . This includes fields like sourcetype, targettype, connid,
585 * list_heads, htab_entries, ???. In this case the side with is_client == 1
586 * needs to be locked first. Changes to conn_id and neighbor also require
587 * removing the conn from the htables first.
589 * Some other fields like htab_entry, some list_head need are locked
590 * outside (e.g. at struct neighbor).
592 struct conn{
593 /* The first member has to be the same as in connlistener (see sock.c)*/
594 __u8 sockstate;
596 #define SOURCE_NONE 0
597 #define SOURCE_IN 1
598 #define SOURCE_SOCK 2
600 #define TARGET_UNCONNECTED 0
601 #define TARGET_OUT 1
602 #define TARGET_SOCK 2
604 __u8 sourcetype:4,
605 targettype:4;
607 __u8 tos;
609 __u8 last_bufferstate:1,
610 in_credit_list:1;
612 __u8 is_client;
615 * isreset values:
616 * 0... connection active
617 * 1... connection is about to be reset, target does not need to be
618 * notified
619 * 2... connection is reset
620 * 3... connection is reset + no pointers to "struct conn *reversedir"
621 * remaining except from this conn
623 __u8 isreset;
625 struct list_head queue_list;
627 struct kref ref;
629 struct mutex rcv_lock;
631 unsigned long jiffies_credit_update;
632 struct list_head credit_list;
633 /* state */
634 __u64 credits;
635 /* credit rates per second, locked by credit_lock (in credit.c) */
636 __u64 crate_in;
637 __u32 crate_out;
639 * This is how much we *want* to forward, not how much we actually do.
640 * 2^31 == 100%
642 __u32 crate_forward;
644 union{
645 struct{
646 struct neighbor *nb;
647 /* list of all connections from this neighbor */
648 struct list_head nb_list;
650 struct sk_buff_head reorder_queue;
652 struct htab_entry htab_entry;
653 __u32 conn_id;
654 __u32 next_seqno;
655 __u32 ooo_packets;
657 /* number of ack sent, not data seqno */
658 __u32 ack_seqno;
660 /* credit rate */
661 __u16 decaytime;
662 __u8 decaytime_seqno;
663 __u8 inorder_ack_needed;
665 __u32 window_seqnolimit;
666 __u32 window_seqnolimit_remote;
668 /* protected by nb->cmsg_lock */
669 struct list_head acks_pending;
671 struct list_head buffer_list;
673 __u32 buffer_init;
674 __u32 buffer_speed;
675 __u32 buffer_ata;
677 __u32 usage_init;
678 __u32 usage_speed;
679 __u32 usage_ata;
680 __u32 usage_reserve;
682 struct speedtracker st;
684 unsigned long jiffies_last_window_set;
686 unsigned long jiffies_last_act;
687 }in;
689 struct{
690 struct list_head cl_list;
691 wait_queue_head_t wait;
692 struct socket *sock;
693 int flags;
695 __u32 crate;
697 __u32 wait_len;
700 * alloclimit, delflush_list, alwait_list,
701 * in_alwait_list are protected by
702 * sock_bufferlimits_lock
704 * sbt may not change unless both sock_bufferlimits_lock
705 * and rcv_lock is held
707 * delay_flush is protocted by rcv_lock
709 __u32 alloclimit;
710 struct sock_buffertracker *sbt;
711 struct list_head delflush_list;
712 struct list_head alwait_list;
713 __u8 in_alwait_list;
714 __u8 delay_flush;
715 }sock;
716 }source;
718 union{
719 struct{
720 __u32 paramlen;
721 __u32 cmdread;
722 __u16 cmd;
723 __u8 paramlen_read;
724 __u8 *cmdparams;
725 char paramlen_buf[4];
727 __u8 in_buffer_wait_list;
728 struct list_head buffer_wait_list;
729 }unconnected;
731 struct{
732 struct neighbor *nb;
733 /* protected by nb->retrans_lock, sorted by seqno */
734 struct list_head retrans_list;
736 /* reverse conn_id lookup */
737 struct htab_entry htab_entry;
739 __u32 conn_id;
740 __u32 seqno_nextsend;
741 __u32 seqno_acked;
742 __u32 seqno_windowlimit;
744 struct resume_block rb;
746 __u16 decaytime_last;
747 __u8 decaytime_seqno;
748 __u8 decaytime_send_allowed;
749 }out;
751 struct{
752 wait_queue_head_t wait;
754 __u8 credituser;
755 }sock;
756 }target;
758 struct{
759 struct list_head items;
760 struct data_buf_item *lastread;
761 __u32 first_offset;
763 __u32 totalsize;
764 __u32 overhead;
765 __u32 read_remaining;
767 __u16 last_read_offset;
769 __u16 cpacket_buffer;/* including overhead */
770 }data_buf;
772 struct conn *reversedir;
775 /* inside skb->cb */
776 struct skb_procstate{
777 union{
778 struct{
779 struct work_struct work;
780 }rcv;
782 struct{
783 __u32 offset;
784 }announce;
786 struct{
787 __u32 seqno;
788 }rcv2;
789 }funcstate;
792 struct sock_buffertracker {
793 struct list_head lh;
795 uid_t uid;
796 __u64 usage;
798 struct list_head delflush_conns;
799 struct list_head waiting_conns;
801 struct kref ref;
805 /* common.c */
806 extern atomic_t num_conns;
808 extern __u8 __attribute__((const)) enc_log_64_11(__u32 window_bytes);
810 extern __u32 __attribute__((const)) dec_log_64_11(__u8 window);
812 extern __u16 __attribute__((const)) enc_log_300_24(__u64 value);
814 extern __u64 __attribute__((const)) dec_log_300_24(__u16 value);
816 extern __u64 __attribute__((const)) multiply_div(__u64 a, __u64 b, __u64 c);
818 extern char *htable_get(struct htable *ht, __u32 key, void *searcheditem);
820 extern int htable_delete(struct htable *ht, __u32 key, void *searcheditem,
821 void (*free) (struct kref *ref));
823 extern void htable_insert(struct htable *ht, char *newelement, __u32 key);
825 extern void htable_init(struct htable *ht, int (*matches)(void *htentry,
826 void *searcheditem), __u32 entry_offset,
827 __u32 kref_offset);
829 extern struct conn *get_conn_reverse(struct neighbor *nb, __u32 conn_id);
831 extern void insert_reverse_connid(struct conn *trgt_out_ll);
833 extern struct conn *get_conn(__u32 conn_id);
835 extern void _set_last_act(struct conn *src_in_l);
837 extern void free_conn(struct kref *ref);
839 extern int conn_init_out(struct conn *trgt_unconn_ll, struct neighbor *nb);
841 extern void conn_init_sock_source(struct conn *cn);
843 extern void conn_init_sock_target(struct conn *cn);
845 extern void close_port(struct connlistener *listener);
847 extern struct connlistener *open_port(__be64 port);
849 extern int connect_port(struct conn *trtg_unconn_l, __be64 port);
851 extern int connect_neigh(struct conn *trtg_unconn_l,
852 __u16 addrtypelen, __u8 *addrtype,
853 __u16 addrlen, __u8 *addr);
855 extern struct conn* alloc_conn(gfp_t allocflags);
857 extern void reset_conn(struct conn *cn);
859 /* credits.c */
860 extern __u32 creditrate_initial(void);
862 extern int refresh_conn_credits(struct conn *conn, int fromperiodic,
863 int locked);
865 extern void set_creditrate_initial(struct neighbor *nb, __u32 debitrate);
867 extern void set_conn_in_decaytime(struct neighbor *nb, __u32 conn_id,
868 struct conn *src_in, __u8 decaytime_seqno, __u16 decaytime);
870 extern void connreset_credits(struct conn *cn);
872 extern void __init credits_init(void);
874 /* neighbor.c */
875 extern void neighbor_free(struct kref *ref);
877 extern int is_from_nb(struct sk_buff *skb, struct neighbor *nb);
879 extern struct neighbor *get_neigh_by_mac(struct sk_buff *skb);
881 extern struct neighbor *find_neigh(__u16 addrtypelen, __u8 *addrtype,
882 __u16 addrlen, __u8 *addr);
884 extern __u32 generate_neigh_list(char *buf, __u32 buflen, __u32 limit,
885 __u32 offset);
887 extern int get_neigh_state(struct neighbor *nb);
889 extern void ping_resp(struct neighbor *nb, __u32 cookie, __u32 respdelay);
891 extern __u32 add_ping_req(struct neighbor *nb, unsigned long *last_ping_time);
893 extern void unadd_ping_req(struct neighbor *nb, __u32 cookie,
894 unsigned long last_ping_time);
896 extern void set_busy_till(struct neighbor *nb, int initial);
898 extern int time_to_send_ping(struct neighbor *nb);
900 extern int get_next_ping_time(struct neighbor *nb);
902 extern int force_ping(struct neighbor *nb);
904 extern void rcv_announce(struct sk_buff *skb);
906 extern int send_announce_qos(struct announce_data *ann);
908 extern void announce_data_free(struct kref *ref);
910 extern int __init cor_neighbor_init(void);
912 /* rcv.c */
913 extern __u8 get_window(struct conn *cn, struct neighbor *expectedsender,
914 __u32 expected_connid, int from_acksend);
916 extern void reset_bufferusage(struct conn *cn);
918 extern void refresh_speedstat(struct conn *l_src_in, __u32 written);
920 extern void drain_ooo_queue(struct conn *l_src_in);
922 extern void conn_rcv_buildskb(struct neighbor *nb, char *data, __u32 datalen,
923 __u32 conn_id, __u32 seqno);
925 extern int __init cor_rcv_init(void);
927 /* kpacket_parse.c */
928 extern void kernel_packet(struct neighbor *nb, struct sk_buff *skb,
929 __u32 seqno);
931 /* kpacket_gen.c */
932 extern void controlmsg_workfunc(struct work_struct *work);
934 struct control_msg_out;
936 #define ACM_PRIORITY_LOW 1 /* oom recovery easy */
937 #define ACM_PRIORITY_MED 2 /* oom may require recovery on layer 4 */
938 #define ACM_PRIORITY_HIGH 3 /* oom may cause timeouts on layer 3 */
940 extern int may_alloc_control_msg(struct neighbor *nb, int priority);
942 extern struct control_msg_out *alloc_control_msg(struct neighbor *nb,
943 int priority);
945 extern void free_control_msg(struct control_msg_out *cm);
947 extern void retransmit_timerfunc(struct work_struct *work);
949 extern void kern_ack_rcvd(struct neighbor *nb, __u32 seqno);
951 extern int send_messages(struct neighbor *nb, int resume);
953 extern void controlmsg_workfunc(struct work_struct *work);
955 extern void controlmsg_timerfunc(unsigned long arg);
957 extern void schedule_controlmsg_timer(struct neighbor *nb);
959 extern void send_pong(struct neighbor *nb,
960 __u32 cookie);
962 extern int send_reset_conn(struct neighbor *nb, __u32 conn_id_reset,
963 __u32 conn_id_unknown, int lowprio);
965 extern void send_ack(struct neighbor *nb,
966 __u32 seqno);
968 extern void send_ack_conn_ifneeded(struct conn *src_in_l);
970 extern void send_ack_conn_ooo(struct control_msg_out *cm, struct conn *src_in_l,
971 __u32 conn_id, __u32 seqno_ooo, __u32 length);
973 extern void send_decaytime(struct conn *trgt_out_l, int force, __u16 decaytime);
975 extern void free_ack_conns(struct conn *src_in_l);
977 extern void send_connect_success(struct control_msg_out *cm, __u32 rcvd_conn_id,
978 __u32 gen_conn_id, __u32 init_seqno, struct conn *src_in);
980 extern void send_connect_nb(struct control_msg_out *cm, __u32 conn_id,
981 __u32 init_seqno, struct conn *src_in);
983 extern void send_conndata(struct control_msg_out *cm, __u32 conn_id,
984 __u32 seqno, char *data_orig, char *data, __u32 datalen);
986 extern void send_connid_unknown(struct neighbor *nb, __u32 conn_id);
988 extern void __init cor_kgen_init(void);
990 /* cpacket_parse.c */
991 extern void free_cpacket_buffer(__s32 amount);
993 extern void connreset_cpacket_buffer(struct conn *trtg_unconn_l);
995 extern int encode_len(char *buf, int buflen, __u32 len);
997 extern int decode_len(char *buf, int buflen, __u32 *len);
999 extern void parse(struct conn *trtg_unconn, int fromresume);
1001 extern int __init cor_cpacket_init(void);
1003 /* snd.c */
1004 extern int destroy_queue(struct net_device *dev);
1006 extern int create_queue(struct net_device *dev);
1008 #define QOS_CALLER_KPACKET 0
1009 #define QOS_CALLER_CONN_RETRANS 1
1010 #define QOS_CALLER_ANNOUNCE 2
1011 #define QOS_CALLER_CONN 3
1013 extern void qos_enqueue(struct net_device *dev, struct resume_block *rb,
1014 int caller);
1016 extern void qos_remove_conn(struct conn *cn);
1018 extern struct sk_buff *create_packet(struct neighbor *nb, int size,
1019 gfp_t alloc_flags, __u32 conn_id, __u32 seqno);
1021 extern void cancel_retrans(struct conn *trgt_out_l);
1023 extern void retransmit_conn_timerfunc(struct work_struct *work);
1025 extern void conn_ack_ooo_rcvd(struct neighbor *nb, __u32 conn_id,
1026 struct conn *trgt_out, __u32 seqno_ooo, __u32 length);
1028 extern void conn_ack_rcvd(struct neighbor *nb, __u32 conn_id,
1029 struct conn *trgt_out, __u32 seqno, int setwindow, __u8 window);
1031 #define RC_FLUSH_CONN_OUT_OK 0
1032 #define RC_FLUSH_CONN_OUT_OK_SENT 1
1033 #define RC_FLUSH_CONN_OUT_CONG 2
1034 #define RC_FLUSH_CONN_OUT_CREDITS 3
1035 #define RC_FLUSH_CONN_OUT_OOM 4
1036 extern int flush_out(struct conn *trgt_out_l, int fromqos, __u32 creditsperbyte);
1038 extern int __init cor_snd_init(void);
1040 /* forward.c */
1041 extern void databuf_init(struct conn *cn_init);
1043 extern void databuf_free(struct conn *cn_l);
1045 extern void reset_seqno(struct conn *cn_l, __u32 initseqno);
1047 extern void databuf_pull(struct conn *cn_l, char *dst, int len);
1049 extern size_t databuf_pulluser(struct conn *trgt_sock_l, struct msghdr *msg);
1051 extern void databuf_unpull(struct conn *trgt_out_l, __u32 bytes);
1053 extern void databuf_pullold(struct conn *trgt_out_l, __u32 startpos, char *dst,
1054 int len);
1056 extern void databuf_ack(struct conn *trgt_out_l, __u32 pos);
1058 extern void databuf_ackread(struct conn *cn_l);
1060 __s64 receive_userbuf(struct conn *src_sock_l, struct msghdr *msg, __u32 maxcpy,
1061 __u32 maxusage);
1063 extern void receive_cpacketresp(struct conn *trtg_unconn_l, char *buf, int len);
1065 extern int receive_skb(struct conn *src_in_l, struct sk_buff *skb);
1067 extern void wake_sender(struct conn *cn);
1069 extern void flush_buf(struct conn *cn);
1071 extern void __init forward_init(void);
1073 /* sock.c */
1074 extern struct mutex sock_bufferlimits_lock;
1076 extern void connreset_sbt(struct conn *cn);
1078 extern void unreserve_sock_buffer(struct conn *cn);
1081 static inline struct skb_procstate *skb_pstate(struct sk_buff *skb)
1083 return (struct skb_procstate *) &(skb->cb[0]);
1086 static inline struct sk_buff *skb_from_pstate(struct skb_procstate *ps)
1088 return (struct sk_buff *) (((char *)ps) - offsetof(struct sk_buff,cb));
1092 static inline __u32 mss(struct neighbor *nb)
1094 return nb->dev->mtu - LL_RESERVED_SPACE(nb->dev) - 9;
1098 static inline void put_u64(char *dst, __u64 value, int convbo)
1100 char *p_value = (char *) &value;
1102 if (convbo)
1103 value = cpu_to_be64(value);
1105 dst[0] = p_value[0];
1106 dst[1] = p_value[1];
1107 dst[2] = p_value[2];
1108 dst[3] = p_value[3];
1109 dst[4] = p_value[4];
1110 dst[5] = p_value[5];
1111 dst[6] = p_value[6];
1112 dst[7] = p_value[7];
1115 static inline void put_u32(char *dst, __u32 value, int convbo)
1117 char *p_value = (char *) &value;
1119 if (convbo)
1120 value = cpu_to_be32(value);
1122 dst[0] = p_value[0];
1123 dst[1] = p_value[1];
1124 dst[2] = p_value[2];
1125 dst[3] = p_value[3];
1128 static inline void put_u16(char *dst, __u16 value, int convbo)
1130 char *p_value = (char *) &value;
1132 if (convbo)
1133 value = cpu_to_be16(value);
1135 dst[0] = p_value[0];
1136 dst[1] = p_value[1];
1139 static inline char *cor_pull_skb(struct sk_buff *skb, unsigned int len)
1141 char *ptr = skb_pull(skb, len);
1143 if(unlikely(ptr == 0))
1144 return 0;
1146 return ptr - len;
1149 static inline int is_conn_in(struct conn *cn_l, struct neighbor *nb,
1150 __u32 conn_id)
1152 if (unlikely(unlikely(cn_l->sourcetype != SOURCE_IN) ||
1153 unlikely(cn_l->source.in.nb != nb) ||
1154 unlikely(cn_l->source.in.conn_id != conn_id) ||
1155 unlikely(cn_l->isreset != 0)))
1156 return 0;
1157 return 1;
1160 static inline void set_last_act(struct conn *src_in_l)
1162 unsigned long jiffies_tmp = jiffies;
1164 BUG_ON(src_in_l->sourcetype != SOURCE_IN);
1166 if (unlikely(time_after(src_in_l->source.in.jiffies_last_act +
1167 HZ * CONN_ACTIVITY_UPDATEINTERVAL_SEC,
1168 jiffies_tmp)))
1169 _set_last_act(src_in_l);
1173 static inline int seqno_before(__u32 seqno1, __u32 seqno2)
1175 return (seqno1 - seqno2) >= (1 << 31);
1178 static inline int seqno_before_eq(__u32 seqno1, __u32 seqno2)
1180 return (seqno1 == seqno2) || ((seqno1 - seqno2) >= (1 << 31));
1183 static inline int seqno_after(__u32 seqno1, __u32 seqno2)
1185 return (seqno1 - seqno2) < (1 << 31);
1188 static inline int seqno_after_eq(__u32 seqno1, __u32 seqno2)
1190 return (seqno1 == seqno2) || ((seqno1 - seqno2) < (1 << 31));
1193 static inline int ktime_before(ktime_t time1, ktime_t time2)
1195 return ktime_to_ns(time1) - ktime_to_ns(time2) < 0;
1198 static inline int ktime_before_eq(ktime_t time1, ktime_t time2)
1200 return ktime_to_ns(time1) - ktime_to_ns(time2) <= 0;
1203 static inline int ktime_after(ktime_t time1, ktime_t time2)
1205 return ktime_to_ns(time1) - ktime_to_ns(time2) > 0;
1208 static inline int ktime_after_eq(ktime_t time1, ktime_t time2)
1210 return ktime_to_ns(time1) - ktime_to_ns(time2) >= 0;
1213 static inline __s64 ktime_to_ms(ktime_t time)
1215 return (ktime_to_ns(time) + 500000) / 1000000;