credit exchange
[cor_2_6_31.git] / net / cor / cor.h
blob96ceef5ca9c13d37a639bcda158adca3f846c15b
1 /*
2 * Connection oriented routing
3 * Copyright (C) 2007-2010 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>
30 #include "settings.h"
33 /* options */
34 #define PIDOUT_NEWCONN 16
35 #define PIDOUT_SENDDEF_THRES 8
36 #define PIDOUT_SENDDEF_COUNT 16
40 #define ETH_P_COR 0x1022
41 #define AF_COR 37
42 #define PF_COR AF_COR
44 #define SOCKADDRTYPE_PORT 1
45 struct cor_sockaddr {
46 int type;
48 union {
49 __be64 port;
50 } addr;
53 #define MAX_CONN_CMD_LEN 4096
56 #define PACKET_TYPE_ANNOUNCE 1
57 #define PACKET_TYPE_DATA 2
60 * Kernel packet data - these commands are sent by the neighbor
61 * The end nodes may cause these commands to be sent, but they see them beyond
62 * the first hop.
65 /* KP_PADDING[1] */
66 #define KP_PADDING 1
69 * KP_PING[1] cookie[4]
70 * KP_PONG[1] cookie[4] respdelay[4]
72 * This is needed to find out whether the other node is reachable. After a new
73 * neighbor is seen, ping requests are sent and the neighbor is only reachable
74 * after a few pongs are received. These requests are also used to find out
75 * whether a neighber is gone.
77 * respdelay:
78 * The receiver of a ping may delay the sending of the pong e.g. to create
79 * bigger kernel packets. The respdelay is the time in microseconds the packet
80 * was delayed.
82 #define KP_PING 2
83 #define KP_PONG 3
85 /* KP_ACK[1] seqno[4] */
86 #define KP_ACK 4
89 * KP_ACK_CONN[1] conn_id[4] flags[1] seqno[4] window[1]
90 * KP_ACK_CONN_OOO[1] conn_id[4] seqno[4] window[1] seqno_ooo[4] length[4]
92 * conn_id is the conn_id we use if we sent something through this conn and
93 * *not* the conn_id that the neighbor used to send us the data
95 * seqno = the seqno which is expected in the next non-out-of-order packet
96 * seqno_ooo, length = in case
98 * window = amount of data which can be sent without receiving the next ack
99 * packets with lower seqno do not overwrite the last window size
100 * note: the other side may also reduce the window size
101 * decode:
102 * 0 = 0
103 * 1...255 = 64*2^((value-1)/11) end result is rounded down to an integer
105 * 32* 2 ^ ((value-1)/8)
108 #define KP_ACK_CONN 5
110 #define KP_ACK_CONN_FLAGS_SEQNO 1
111 #define KP_ACK_CONN_FLAGS_WINDOW 2
112 #define KP_ACK_CONN_FLAGS_OOO 12 /* 4+8 */
113 #define KP_ACK_CONN_FLAGS_CREDITS 16
114 #define KP_ACK_CONN_FLAGS_PING 32
116 static inline __u8 ooolen_to_flags(__u32 len)
118 if (len == 0)
119 return 0;
120 if (len < 256)
121 return 4;
122 if (len < 65536)
123 return 8;
124 return 12;
127 static inline int ooolen(__u8 flags)
129 int len = ((flags & KP_ACK_CONN_FLAGS_OOO) >> 2);
130 if (unlikely(len == 3))
131 return 4;
132 return len;
135 static inline int ack_conn_len(__u8 flags)
137 int len = 0;
138 if ((flags & KP_ACK_CONN_FLAGS_SEQNO) != 0) {
139 len += 4;
140 if ((flags & KP_ACK_CONN_FLAGS_WINDOW) != 0)
141 len++;
144 if (ooolen(flags) != 0) {
145 len += 4;
146 len += ooolen(flags);
149 if (flags & KP_ACK_CONN_FLAGS_CREDITS)
150 len += 2;
152 return len;
156 * NOTE on connection ids:
157 * connection ids + init seqnos we send are used for the receive channel
158 * connection ids + init seqnos we receive are used for the send channel
162 * incoming connection
163 * KP_CONNECT[1] conn_id[4] init_seqno[4] window[1]
165 #define KP_CONNECT 6
168 * incoming connection successful,
169 * the first conn_id is the same as previously sent/received in KP_CONNECT
170 * the second conn_id is generated by us and used for the other direction
171 * KP_CONNECT_SUCCESS[1] conn_id[4] conn_id[4] init_seqno[4] window[1]
173 #define KP_CONNECT_SUCCESS 7
175 /* KP_CONN_DATA[1] conn_id[4] seqno[4] length[2] data[length] */
176 #define KP_CONN_DATA 8
179 * { KP_RESET_CONN[1] conn_id[4] }
180 * We send this, if there is an established connection we want to close.
182 #define KP_RESET_CONN 9
185 * KP_CONNID_UNKNOWN[1] sent_conn_id[4]
186 * We send this, if we receive an invalid conn_id
188 #define KP_CONNID_UNKNOWN 10
191 * KP_PING_ALL_CONNS[1]
192 * We send this, if we we lost a conn, but could not send reset_conn and
193 * connid_unknown
195 #define KP_PING_ALL_CONNS 11
198 * KP_SET_MAX_CMSG_DELAY[1] delay[4]
199 * Sent after connecting and at any change
200 * delay in specifies in microsecs
202 #define KP_SET_MAX_CMSG_DELAY 12
206 * Connection data which in interpreted when connection has no target yet
207 * These commands are sent by the end node.
209 * Format:
210 * cmd[2] length[1-4] parameter[length]
211 * unrecogniced commands are ignored
212 * parameters which are longer than expected are ignored as well
215 /* outgoing connection: CD_CONNECT_NB[2] length[1-4]
216 * addrtypelen[1-4] addrlen[1-4] addrtype[addrtypelen] addr[addrlen] */
217 #define CD_CONNECT_NB 1
219 /* connection to local open part: CD_CONNECT_PORT[2] length[1-4] port[8] */
220 #define CD_CONNECT_PORT 2
223 * CD_LIST_NEIGH sends CDR_BINDATA if the command was successful. The response
224 * format is:
226 * totalneighs[1-4] response_rows[1-4]
227 * numfields[1-4] (field[2] fieldlen[1-4])[numfields]
228 * rows[responserows]:
229 * fieldlen[1-4], only if fieldlen in the header was "0"
230 * fielddata[fieldlen]
232 * Neighbors have to be sorted by uptime, new neighbors first. This is so that
233 * the routing daemon can easily find out whether there are new neighbors. It
234 * only needs to send a query with offset 0. If the totalneighs stays the same
235 * while new were added, a connection to another neighbor was lost.
237 * Future versions may append data to field definition. Therefore clients must
238 * silently discard data at the end they do not expect.
241 /* list connected neighbors: CD_LIST_NEIGH[2] length[1-4] limit[1-4]
242 * offset[1-4] */
243 #define CD_LIST_NEIGH 3
246 * numaddr[1-4] (addrtypelen[1-4] addrlen[1-4] addrtype[addrtypelen]
247 * addr[addrlen])[numaddr]
249 #define LIST_NEIGH_FIELD_ADDR 1
252 * latency_in_microsecs[4]
253 * Only raw network latency in measured. Delays caused by the credit system are
254 * *not* included.
256 #define LIST_NEIGH_FIELD_LATENCY 2
260 * CD_SET_TOS[2] length[1-4] forward_tos[1] backward_tos[1]
261 * Only 2 bits of the tos flags are used, the highers 6 bits are ignored.
263 #define CD_SET_TOS 4
265 #define TOS_NORMAL 0
266 #define TOS_LATENCY 1
267 #define TOS_THROUGHPUT 2
268 #define TOS_PRIVACY 3
273 * Connection data response
274 * Format is the same as with connection data
278 * CDR_EXECOK[1]
280 #define CDR_EXECOK 1
283 * CDR_EXECFAILED[1] reasoncode[2]
284 * reasontextlength[1-4] reasontext[reasontextlength]
285 * reasontextlength may be 0
287 #define CDR_EXECFAILED 2
288 #define CDR_EXECFAILED_UNKNOWN_COMMAND 1
289 #define CDR_EXECFAILED_PERMISSION_DENIED 2
290 #define CDR_EXECFAILED_TEMPORARILY_OUT_OF_RESSOURCES 3
291 #define CDR_EXECFAILED_CMD_TOO_SHORT 4
292 #define CDR_EXECFAILED_CMD_TOO_LONG 5
293 #define CDR_EXECFAILED_TARGETADDRTYPE_UNKNOWN 6
294 #define CDR_EXECFAILED_TARGETADDR_DOESNTEXIST 7
295 #define CDR_EXECFAILED_TARGETADDR_PORTCLOSED 8
296 #define CDR_EXECFAILED_LISTENERQUEUE_FULL 9
297 #define CDR_EXECFAILED_ILLEGAL_COMMAND 10
300 * must be sent after CDR_EXEC{OK|FAILED}
301 * CDR_EXEOK_BINDATA[1] bindatalen[1-4] bindata[bindatalen] */
302 #define CDR_BINDATA 3
305 * sending 2^32 credits per millisec means that credits the neighbor owns
306 * should be halfed after 1 minute
308 * ((x - 4294967295)/x) ^ 60000 = 0.5
309 * (x-4294967295)/x = 0.5**(1/60000)
310 * x/x - 4294967295/x = 0.5**(1/60000)
311 * 1 - 0.5**(1/60000) = 4294967295/x
312 * x = 4294967295 / (1 - 0.5**(1/60000))
314 #define CREDITS_TOTAL (1LL << 63)
318 /* result codes for rcv.c/proc_packet */
319 #define RC_DROP 0
320 #define RC_FINISHED 1
322 #define RC_RCV1_ANNOUNCE 2
323 #define RC_RCV1_KERNEL 3
324 #define RC_RCV1_CONN 4
326 struct htab_entry{
327 /* start of next element, *not* next htab_entry */
328 void *next;
331 struct htable{
332 struct htab_entry **htable;
333 __u32 htable_size;
334 __u32 cell_size;
335 __u32 num_elements;
337 int (*matches)(void *htentry, void *searcheditem);
338 __u32 key_offset;
339 __u32 entry_offset;
340 __u32 kref_offset;
343 struct resume_block{
344 struct list_head lh;
345 int in_queue;
348 struct announce_data{
349 struct kref ref;
351 struct list_head lh;
352 struct net_device *dev;
353 struct delayed_work announce_work;
354 struct announce *ann;
355 struct resume_block rb;
357 __u32 curr_announce_msg_offset;
358 __u64 scheduled_announce_timer;
361 struct ping_cookie{
362 unsigned long time;
363 __u32 cookie;
364 __u8 pongs; /* count of pongs for pings sent after this one */
367 #define NEIGHBOR_STATE_INITIAL 0
368 #define NEIGHBOR_STATE_ACTIVE 1
369 #define NEIGHBOR_STATE_STALLED 2
370 #define NEIGHBOR_STATE_KILLED 3
372 struct neighbor{
373 struct list_head nb_list;
375 struct kref ref;
377 struct net_device *dev;
378 char mac[MAX_ADDR_LEN];
380 char *addr;
381 __u16 addrlen;
383 struct delayed_work cmsg_timer;
384 struct mutex cmsg_lock;
385 struct list_head control_msgs_out;
387 * urgent messages; These are sent even if the neighbor state is not
388 * active. If the queue gets full, the oldest ones are dropped. It thus
389 * may only contain messages which are allowed to be dropped.
391 struct list_head ucontrol_msgs_out;
392 unsigned long timeout;
393 __u32 cmlength;
394 __u32 ucmlength;
396 atomic_t cmcnt; /* size of queue + retransmits */
397 atomic_t ucmcnt; /* size of queue only */
399 __u8 ping_all_conns;
400 __u8 max_cmsg_delay_sent;
402 /* see snd.c/qos_queue */
403 /* protected by cmsg_lock */
404 __u8 kp_allmsgs;
406 /* procected by queues_lock */
407 struct resume_block rb_kp;
408 struct resume_block rb_cr;
410 struct mutex pingcookie_lock;
411 unsigned long last_ping_time;
412 __u32 ping_intransit;
413 struct ping_cookie cookies[PING_COOKIES_PER_NEIGH];
414 __u32 lastcookie;
415 atomic_t latency; /* microsecs */
416 atomic_t max_remote_cmsg_delay; /* microsecs */
418 spinlock_t state_lock;
419 union {
420 __u64 last_state_change;/* initial state */
422 * last_roundtrip:
423 * time of the last sent packet which has been acked or
424 * otherwise responded to (e.g. pong)
426 unsigned long last_roundtrip;/* active/stalled state */
427 }state_time;
428 __u8 state;
429 __u16 ping_success;
431 struct delayed_work stalltimeout_timer;
432 __u8 str_timer_pending;
435 atomic_t kpacket_seqno;
436 atomic_t ooo_packets;
438 spinlock_t credits_lock;
439 unsigned long jiffies_credit_update;
440 unsigned long jiffies_credit_decay;
442 /* we only keep track on how much the other side may spend */
443 __u64 credits;
444 __u32 credits_fract;
445 /* credit rates are in credits/sec */
446 __u32 creditrate_initial;
447 __u64 creditrate_earning;
448 __u64 creditrate_spending;
451 * connecions which receive data from/send data to this node
452 * used when terminating all connections of a neighbor
454 struct mutex conn_list_lock;
455 struct list_head rcv_conn_list;
456 struct list_head snd_conn_list;
457 __u32 num_send_conns;
460 * used for ping_all conns, if not zero this is the next conn we need to
461 * ping, protected by conn_list_lock
463 struct conn *next_ping_conn;
464 __u32 ping_conns_remaining;
465 __u32 ping_conns_retrans_remaining;
466 __u32 pong_conns_expected;
467 unsigned long ping_conn_completed; /* jiffies */
470 * the timer has to be inited when adding the neighbor
471 * init_timer(struct timer_list * timer);
472 * add_timer(struct timer_list * timer);
474 spinlock_t retrans_lock;
475 struct delayed_work retrans_timer_conn;
476 struct delayed_work retrans_timer;
477 __u8 retrans_timer_conn_running;
478 __u8 retrans_timer_running;
480 struct list_head retrans_list;
481 struct list_head retrans_list_conn;
483 struct conn *firstboundconn;
486 struct cor_sched_data{
487 spinlock_t lock;
488 struct list_head conn_list;
489 struct sk_buff_head requeue_queue;
492 #define TYPE_BUF 0
493 #define TYPE_SKB 1
495 struct data_buf_item{
496 struct list_head buf_list;
498 union {
499 struct {
500 char *buf;
501 __u16 datalen;
502 __u16 buflen;
504 }buf;
506 struct sk_buff *skb;
507 }data;
509 __u8 type;
512 struct connlistener;
514 struct bindnode{
515 struct list_head lh;
516 struct connlistener *owner;
517 __be64 port;
520 #define SOCKSTATE_LISTENER 1
521 #define SOCKSTATE_CONN 2
523 struct sock_hdr {
524 /* The first member of connlistener/conn (see sock.c) */
525 __u8 sockstate;
528 struct connlistener {
529 /* The first member has to be the same as in conn (see sock.c) */
530 __u8 sockstate;
531 struct bindnode *bn;
532 struct mutex lock;
533 int queue_maxlen;
534 int queue_len;
535 struct list_head conn_queue;
536 wait_queue_head_t wait;
540 struct speedtracker{
541 __u64 speed;/* bytes*65536/jiffie */
542 unsigned long jiffies_last_update;
543 __u32 bytes_curr;
547 * There are 2 conn objects per bi-directional connection. They refer to each
548 * other with in the reversedir field. To distinguish them, the variables on
549 * the stack are usually called rconn and sconn. rconn refers to the conn object
550 * which has received a command. sconn is the other conn object.
552 struct conn{
553 /* The first member has to be the same as in connlistener (see sock.c)*/
554 __u8 sockstate;
556 #define SOURCE_NONE 0
557 #define SOURCE_IN 1
558 #define SOURCE_SOCK 2
560 #define TARGET_UNCONNECTED 0
561 #define TARGET_OUT 1
562 #define TARGET_SOCK 2
564 __u8 sourcetype:4,
565 targettype:4;
567 __u8 tos;
569 __u8 last_bufferstate:1,
570 in_credit_list:1;
573 * isreset values:
574 * 0... connection active
575 * 1... connection is about to be reset, target does not need to be
576 * notified
577 * 2... connection is reset
578 * 3... connection is reset + no pointers to "struct conn *reversedir"
579 * remaining except from this conn
581 atomic_t isreset;
583 struct list_head queue_list;
585 struct kref ref;
588 * locking order:
589 * 1) If both sides are SOCK, the side with source.sock.is_client == 1
590 * has to be locked first. This is needed for credits.
591 * 2) If one side is NONE/UNCONNECTED and the direction with
592 * TARGET_UNCONNECTED has to be locked first This is needed for
593 * changing source/targettype, credit flow and TARGET_UNCONNECTED
594 * generating responses.
595 * 3) If one side is SOCK and the other is IN/OUT, TARGET_SOCK has to be
596 * locked first.
597 * 4) If data is forwarded, (both sides are IN/OUT), only one direction
598 * may be locked.
600 struct mutex rcv_lock;
602 unsigned long jiffies_credit_update;
603 struct list_head credit_list;
604 /* state */
605 __u64 credits;
606 /* credit rates per second, locked by credit_lock (in credit.c) */
607 __u64 crate_in;
608 __u32 crate_out;
610 * This is how much we *want* to forward, not how much we actually do.
611 * 2^32 == 100%
613 __u32 crate_forward;
615 union{
616 struct{
617 struct neighbor *nb;
618 /* list of all connections from this neighbor */
619 struct list_head nb_list;
621 struct sk_buff_head reorder_queue;
623 struct htab_entry htab_entry;
624 __u32 conn_id;
625 __u32 next_seqno;
626 __u32 ooo_packets;
628 atomic_t pong_awaiting;
630 /* credit rate */
631 __u16 decaytime;
632 __u8 decaytime_seqno;
634 __u32 window_seqnolimit_max;
635 __u32 window_seqnolimit_last;
637 struct list_head buffer_list;
639 __u32 buffer_init;
640 __u32 buffer_speed;
641 __u32 buffer_ata;
643 __u32 usage_init;
644 __u32 usage_speed;
645 __u32 usage_ata;
646 __u32 usage_reserve;
648 struct speedtracker st;
650 unsigned long jiffies_last_window_set;
651 }in;
653 struct{
654 struct list_head cl_list;
655 wait_queue_head_t wait;
656 struct socket *sock;
657 int flags;
659 __u32 crate;
660 __u32 alloclimit;
661 struct sock_buffertracker *sbt;
662 struct list_head delflush_list;
663 struct list_head alwait_list;
664 __u8 in_alwait_list;
665 __u8 delay_flush;
666 __u8 is_client;
667 __u32 wait_len;
668 }sock;
669 }source;
671 union{
672 struct{
673 __u32 paramlen;
674 __u32 cmdread;
675 __u16 cmd;
676 __u8 paramlen_read;
677 __u8 *cmdparams;
678 char paramlen_buf[4];
680 __u8 in_buffer_wait_list;
681 struct list_head buffer_wait_list;
682 }unconnected;
684 struct{
685 /* has to be first (because it is first in target
686 * kernel too)
688 struct neighbor *nb;
689 /* list of all connections to this neighbor */
690 struct list_head nb_list;
691 /* protected by nb->retrans_lock, sorted by seqno */
692 struct list_head retrans_list;
694 /* reverse conn_id lookup */
695 struct htab_entry htab_entry;
697 __u32 conn_id;
698 __u32 seqno_nextsend;
699 __u32 seqno_acked;
700 __u32 seqno_windowlimit;
702 struct resume_block rb;
704 __u16 decaytime_last;
705 __u8 decaytime_seqno;
706 __u8 decaytime_send_allowed;
707 }out;
709 struct{
710 wait_queue_head_t wait;
712 __u8 credituser;
713 }sock;
714 }target;
716 struct{
717 struct list_head items;
718 struct data_buf_item *lastread;
719 __u32 first_offset;
721 __u32 totalsize;
722 __u32 overhead;
723 __u32 read_remaining;
725 __u16 last_read_offset;
727 __u16 cpacket_buffer;/* including overhead */
728 }data_buf;
730 struct conn *reversedir;
733 /* inside skb->cb */
734 struct skb_procstate{
735 union{
736 struct{
737 struct work_struct work;
738 }rcv;
740 struct{
741 __u32 offset;
742 }announce;
744 struct{
745 __u32 seqno;
746 }rcv2;
747 }funcstate;
750 struct sock_buffertracker {
751 struct list_head lh;
753 uid_t uid;
754 __u64 usage;
756 struct list_head delflush_conns;
757 struct list_head waiting_conns;
759 struct kref ref;
763 /* common.c */
764 extern atomic_t num_conns;
766 extern __u8 enc_log_64_11(__u32 window_bytes);
768 extern __u32 dec_log_64_11(__u8 window);
770 extern __u16 enc_log_300_24(__u64 value);
772 extern __u64 dec_log_300_24(__u16 value);
774 extern __u64 multiply_div(__u64 a, __u64 b, __u64 c);
776 extern char *htable_get(struct htable *ht, __u32 key, void *searcheditem);
778 extern int htable_delete(struct htable *ht, __u32 key, void *searcheditem,
779 void (*free) (struct kref *ref));
781 extern void htable_insert(struct htable *ht, char *newelement, __u32 key);
783 extern void htable_init(struct htable *ht, int (*matches)(void *htentry,
784 void *searcheditem), __u32 entry_offset,
785 __u32 kref_offset);
787 extern struct conn *get_conn_reverse(struct neighbor *nb, __u32 conn_id);
789 extern void insert_reverse_connid(struct conn *rconn);
791 extern struct conn *get_conn(__u32 conn_id);
793 extern void free_conn(struct kref *ref);
795 extern int conn_init_out(struct conn *rconn, struct neighbor *nb);
797 extern void conn_init_sock_source(struct conn *conn);
799 extern void conn_init_sock_target(struct conn *conn);
801 extern void close_port(struct connlistener *listener);
803 extern struct connlistener *open_port(__be64 port);
805 extern int connect_port(struct conn *rconn, __be64 port);
807 extern int connect_neigh(struct conn *rconn,
808 __u16 addrtypelen, __u8 *addrtype,
809 __u16 addrlen, __u8 *addr);
811 extern struct conn* alloc_conn(gfp_t allocflags);
813 extern void reset_ping(struct conn *rconn);
815 extern void reset_conn(struct conn *conn);
817 /* credits.c */
818 extern __u32 creditrate_initial(void);
820 extern int refresh_conn_credits(struct conn *conn, int fromperiodic,
821 int locked);
823 extern void set_creditrate_initial(struct neighbor *nb, __u32 debitrate);
825 extern void set_conn_in_decaytime(struct conn *rconn, __u8 decaytime_seqno,
826 __u16 decaytime);
828 extern void connreset_credits(struct conn *conn);
830 extern void credits_init(void);
832 /* neighbor.c */
833 extern void neighbor_free(struct kref *ref);
835 extern struct neighbor *get_neigh_by_mac(struct sk_buff *skb);
837 extern struct neighbor *find_neigh(__u16 addrtypelen, __u8 *addrtype,
838 __u16 addrlen, __u8 *addr);
840 extern __u32 generate_neigh_list(char *buf, __u32 buflen, __u32 limit,
841 __u32 offset);
843 extern int get_neigh_state(struct neighbor *nb);
845 extern void ping_resp(struct neighbor *nb, __u32 cookie, __u32 respdelay);
847 extern __u32 add_ping_req(struct neighbor *nb);
849 extern void unadd_ping_req(struct neighbor *nb, __u32 cookie);
851 extern int time_to_send_ping(struct neighbor *nb);
853 extern int force_ping(struct neighbor *nb);
855 extern void rcv_announce(struct sk_buff *skb);
857 extern int send_announce_qos(struct announce_data *ann);
859 extern void announce_data_free(struct kref *ref);
861 extern int __init cor_neighbor_init(void);
863 /* rcv.c */
864 extern __u8 get_window(struct conn *rconn);
866 extern void reset_bufferusage(struct conn *conn);
868 extern void refresh_speedstat(struct conn *rconn, __u32 written);
870 extern void drain_ooo_queue(struct conn *rconn);
872 extern void conn_rcv_buildskb(char *data, __u32 datalen, __u32 conn_id,
873 __u32 seqno);
875 extern int __init cor_rcv_init(void);
877 /* kpacket_parse.c */
878 extern void kernel_packet(struct neighbor *nb, struct sk_buff *skb, __u32 seqno);
880 /* kpacket_gen.c */
881 extern void schedule_controlmsg_timerfunc(struct neighbor *nb);
883 struct control_msg_out;
885 #define ACM_PRIORITY_LOW 1
886 #define ACM_PRIORITY_MED 2
887 #define ACM_PRIORITY_HIGH 3
889 extern int may_alloc_control_msg(struct neighbor *nb, int priority);
891 extern struct control_msg_out *alloc_control_msg(struct neighbor *nb,
892 int priority);
894 extern void free_control_msg(struct control_msg_out *cm);
896 extern void retransmit_timerfunc(struct work_struct *work);
898 extern void kern_ack_rcvd(struct neighbor *nb, __u32 seqno);
900 extern int send_messages(struct neighbor *nb, int allmsgs, int resume);
902 extern void send_pong(struct neighbor *nb,
903 __u32 cookie);
905 extern void send_reset_conn(struct control_msg_out *cm, __u32 conn_id);
907 extern void send_ack(struct neighbor *nb,
908 __u32 seqno);
910 extern void send_ack_conn(struct control_msg_out *cm, struct conn *rconn,
911 __u32 conn_id, __u32 seqno);
913 extern void send_ack_conn_ooo(struct control_msg_out *cm, struct conn *rconn,
914 __u32 conn_id, __u32 seqno_ooo, __u32 length);
916 extern void send_decaytime(struct conn *rconn, int force, __u16 decaytime);
918 extern void send_connect_success(struct control_msg_out *cm, __u32 rcvd_conn_id,
919 __u32 gen_conn_id, __u32 init_seqno, struct conn *rconn);
921 extern void send_connect_nb(struct control_msg_out *cm, __u32 conn_id,
922 __u32 init_seqno, struct conn *sconn);
924 extern void send_conndata(struct control_msg_out *cm, __u32 conn_id,
925 __u32 seqno, char *data_orig, char *data, __u32 datalen);
927 extern void send_connid_unknown(struct control_msg_out *cm, __u32 conn_id);
929 extern void send_ping_all_conns(struct neighbor *nb);
931 extern void cor_kgen_init(void);
933 /* cpacket_parse.c */
934 extern void free_cpacket_buffer(__s32 amount);
936 extern void connreset_cpacket_buffer(struct conn *rconn);
938 extern int encode_len(char *buf, int buflen, __u32 len);
940 extern int decode_len(char *buf, int buflen, __u32 *len);
942 extern void parse(struct conn *rconn, int fromresume);
944 extern int __init cor_cpacket_init(void);
946 /* snd.c */
947 extern int destroy_queue(struct net_device *dev);
949 extern int create_queue(struct net_device *dev);
951 #define QOS_CALLER_KPACKET 0
952 #define QOS_CALLER_CONN_RETRANS 1
953 #define QOS_CALLER_ANNOUNCE 2
954 #define QOS_CALLER_CONN 3
956 extern void qos_enqueue(struct net_device *dev, struct resume_block *rb,
957 int caller);
959 extern void qos_remove_conn(struct conn *rconn);
961 extern struct sk_buff *create_packet(struct neighbor *nb, int size,
962 gfp_t alloc_flags, __u32 conn_id, __u32 seqno);
964 extern void cancel_retrans(struct conn *rconn);
966 extern void retransmit_conn_timerfunc(struct work_struct *work);
968 extern void conn_ack_ooo_rcvd(struct conn *rconn, __u32 seqno_ooo,
969 __u32 length);
971 extern void conn_ack_rcvd(struct conn *rconn, __u32 seqno, int setwindow,
972 __u8 window);
974 #define RC_FLUSH_CONN_OUT_OK 0
975 #define RC_FLUSH_CONN_OUT_OK_SENT 1
976 #define RC_FLUSH_CONN_OUT_CONG 2
977 #define RC_FLUSH_CONN_OUT_CREDITS 3
978 #define RC_FLUSH_CONN_OUT_OOM 4
979 extern int flush_out(struct conn *rconn, int fromqos, __u32 creditsperbyte);
981 extern int __init cor_snd_init(void);
983 /* forward.c */
984 extern void databuf_pull(struct conn *conn, char *dst, int len);
986 extern size_t databuf_pulluser(struct conn *sconn, struct msghdr *msg);
988 extern void databuf_unpull(struct conn *conn, __u32 bytes);
990 extern void databuf_pullold(struct conn *conn, __u32 startpos, char *dst,
991 int len);
993 extern void databuf_ack(struct conn *rconn, __u32 pos);
995 extern void databuf_ackread(struct conn *rconn);
997 extern void flush_buf(struct conn *rconn);
999 extern void reset_seqno(struct conn *conn, __u32 initseqno);
1001 extern void databuf_free(struct conn *conn);
1003 extern void databuf_init(struct conn *conn);
1005 __s64 receive_userbuf(struct conn *rconn, struct msghdr *msg, __u32 maxcpy,
1006 __u32 maxusage);
1008 extern void receive_cpacketresp(struct conn *rconn, char *buf, int len);
1010 extern int receive_skb(struct conn *rconn, struct sk_buff *skb);
1012 extern void wake_sender(struct conn *rconn);
1014 extern void forward_init(void);
1016 /* sock.c */
1017 extern struct mutex sock_bufferlimits_lock;
1019 extern void free_sbt(struct kref *ref);
1021 extern void unreserve_sock_buffer(struct conn *conn);
1024 static inline struct skb_procstate *skb_pstate(struct sk_buff *skb)
1026 return (struct skb_procstate *) &(skb->cb[0]);
1029 static inline struct sk_buff *skb_from_pstate(struct skb_procstate *ps)
1031 return (struct sk_buff *) (((char *)ps) - offsetof(struct sk_buff,cb));
1035 static inline __u32 mss(struct neighbor *nb)
1037 return nb->dev->mtu - LL_RESERVED_SPACE(nb->dev) - 9;
1041 static inline void put_u64(char *dst, __u64 value, int convbo)
1043 char *p_value = (char *) &value;
1045 if (convbo)
1046 value = cpu_to_be64(value);
1048 dst[0] = p_value[0];
1049 dst[1] = p_value[1];
1050 dst[2] = p_value[2];
1051 dst[3] = p_value[3];
1052 dst[4] = p_value[4];
1053 dst[5] = p_value[5];
1054 dst[6] = p_value[6];
1055 dst[7] = p_value[7];
1058 static inline void put_u32(char *dst, __u32 value, int convbo)
1060 char *p_value = (char *) &value;
1062 if (convbo)
1063 value = cpu_to_be32(value);
1065 dst[0] = p_value[0];
1066 dst[1] = p_value[1];
1067 dst[2] = p_value[2];
1068 dst[3] = p_value[3];
1071 static inline void put_u16(char *dst, __u16 value, int convbo)
1073 char *p_value = (char *) &value;
1075 if (convbo)
1076 value = cpu_to_be16(value);
1078 dst[0] = p_value[0];
1079 dst[1] = p_value[1];
1082 static inline char *cor_pull_skb(struct sk_buff *skb, unsigned int len)
1084 char *ptr = skb_pull(skb, len);
1086 if(unlikely(ptr == 0))
1087 return 0;
1089 return ptr - len;
1092 #define S64_MAX 9223372036854775807LL
1093 #define S64_MIN (1LL << 63)