set credits on new connections
[cor_2_6_31.git] / net / cor / cor.h
blobfe4a4980f032a595772cc11b8d78e7038d0b5744
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] seqno_ooo[4]
90 * length[1-4] credits[2]
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 * flags defines which of the following fields are sent
97 * seqno = the seqno which is expected in the next non-out-of-order packet
99 * window = amount of data which can be sent without receiving the next ack
100 * packets with lower seqno do not overwrite the last window size
101 * note: the other side may also reduce the window size
102 * decode:
103 * 0 = 0
104 * 1...255 = 64*2^((value-1)/11) end result is rounded down to an integer
106 * todo 32* 2 ^ ((value-1)/8)
108 * seqno_ooo, length = This packet was received out of order. Maybe a previous
109 * packet has been lost. Out of order data should not be retransmitted.
110 * Multiple ooo packets may be merged into a single ack. Ooo packets may be
111 * partially accepted, so that the length does not cover the full packet and/
112 * or the seqno starts in the middle of a packet
114 * credits = decaytime+seqno
116 #define KP_ACK_CONN 5
118 #define KP_ACK_CONN_FLAGS_SEQNO 1
119 #define KP_ACK_CONN_FLAGS_WINDOW 2
120 #define KP_ACK_CONN_FLAGS_OOO 12 /* 4+8 */
121 #define KP_ACK_CONN_FLAGS_CREDITS 16
122 #define KP_ACK_CONN_FLAGS_PING 32
124 static inline __u8 ooolen_to_flags(__u32 len)
126 if (len == 0)
127 return 0;
128 if (len < 256)
129 return 4;
130 if (len < 65536)
131 return 8;
132 return 12;
135 static inline int ooolen(__u8 flags)
137 int len = ((flags & KP_ACK_CONN_FLAGS_OOO) >> 2);
138 if (unlikely(len == 3))
139 return 4;
140 return len;
143 static inline int ack_conn_len(__u8 flags)
145 int len = 0;
146 if ((flags & KP_ACK_CONN_FLAGS_SEQNO) != 0) {
147 len += 4;
148 if ((flags & KP_ACK_CONN_FLAGS_WINDOW) != 0)
149 len++;
152 if (ooolen(flags) != 0) {
153 len += 4;
154 len += ooolen(flags);
157 if (flags & KP_ACK_CONN_FLAGS_CREDITS)
158 len += 2;
160 return len;
164 * NOTE on connection ids:
165 * connection ids + init seqnos we send are used for the receive channel
166 * connection ids + init seqnos we receive are used for the send channel
168 * ATTENTION: the credit seqno are reversed:
169 * decaytime seqnos we send are used when we send updates
170 * decaytime seqnos we received are used when we receive updates
174 * incoming connection
175 * credits = decaytime+seqno
176 * KP_CONNECT[1] conn_id[4] init_seqno[4] window[1] credits[2]
178 #define KP_CONNECT 6
181 * incoming connection successful,
182 * the first conn_id is the same as previously sent/received in KP_CONNECT
183 * the second conn_id is generated by us and used for the other direction
184 * KP_CONNECT_SUCCESS[1] conn_id[4] conn_id[4] init_seqno[4] window[1]
185 * credits[2]
187 #define KP_CONNECT_SUCCESS 7
189 /* KP_CONN_DATA[1] conn_id[4] seqno[4] length[2] data[length] */
190 #define KP_CONN_DATA 8
193 * { KP_RESET_CONN[1] conn_id[4] }
194 * We send this, if there is an established connection we want to close.
196 #define KP_RESET_CONN 9
199 * KP_CONNID_UNKNOWN[1] sent_conn_id[4]
200 * We send this, if we receive an invalid conn_id
202 #define KP_CONNID_UNKNOWN 10
205 * KP_PING_ALL_CONNS[1]
206 * We send this, if we we lost a conn, but could not send reset_conn and
207 * connid_unknown
209 #define KP_PING_ALL_CONNS 11
212 * KP_SET_MAX_CMSG_DELAY[1] delay[4]
213 * Sent after connecting and at any change
214 * delay in specifies in microsecs
216 #define KP_SET_MAX_CMSG_DELAY 12
220 * Connection data which in interpreted when connection has no target yet
221 * These commands are sent by the end node.
223 * Format:
224 * cmd[2] length[1-4] parameter[length]
225 * unrecogniced commands are ignored
226 * parameters which are longer than expected are ignored as well
229 /* outgoing connection: CD_CONNECT_NB[2] length[1-4]
230 * addrtypelen[1-4] addrlen[1-4] addrtype[addrtypelen] addr[addrlen] */
231 #define CD_CONNECT_NB 1
233 /* connection to local open part: CD_CONNECT_PORT[2] length[1-4] port[8] */
234 #define CD_CONNECT_PORT 2
237 * CD_LIST_NEIGH sends CDR_BINDATA if the command was successful. The response
238 * format is:
240 * totalneighs[1-4] response_rows[1-4]
241 * numfields[1-4] (field[2] fieldlen[1-4])[numfields]
242 * rows[responserows]:
243 * fieldlen[1-4], only if fieldlen in the header was "0"
244 * fielddata[fieldlen]
246 * Neighbors have to be sorted by uptime, new neighbors first. This is so that
247 * the routing daemon can easily find out whether there are new neighbors. It
248 * only needs to send a query with offset 0. If the totalneighs stays the same
249 * while new were added, a connection to another neighbor was lost.
251 * Future versions may append data to field definition. Therefore clients must
252 * silently discard data at the end they do not expect.
255 /* list connected neighbors: CD_LIST_NEIGH[2] length[1-4] limit[1-4]
256 * offset[1-4] */
257 #define CD_LIST_NEIGH 3
260 * numaddr[1-4] (addrtypelen[1-4] addrlen[1-4] addrtype[addrtypelen]
261 * addr[addrlen])[numaddr]
263 #define LIST_NEIGH_FIELD_ADDR 1
266 * latency_in_microsecs[4]
267 * Only raw network latency in measured. Delays caused by the credit system are
268 * *not* included.
270 #define LIST_NEIGH_FIELD_LATENCY 2
274 * CD_SET_TOS[2] length[1-4] forward_tos[1] backward_tos[1]
275 * Only 2 bits of the tos flags are used, the highers 6 bits are ignored.
277 #define CD_SET_TOS 4
279 #define TOS_NORMAL 0
280 #define TOS_LATENCY 1
281 #define TOS_THROUGHPUT 2
282 #define TOS_PRIVACY 3
287 * Connection data response
288 * Format is the same as with connection data
292 * CDR_EXECOK[1]
294 #define CDR_EXECOK 1
297 * CDR_EXECFAILED[1] reasoncode[2]
298 * reasontextlength[1-4] reasontext[reasontextlength]
299 * reasontextlength may be 0
301 #define CDR_EXECFAILED 2
302 #define CDR_EXECFAILED_UNKNOWN_COMMAND 1
303 #define CDR_EXECFAILED_PERMISSION_DENIED 2
304 #define CDR_EXECFAILED_TEMPORARILY_OUT_OF_RESSOURCES 3
305 #define CDR_EXECFAILED_CMD_TOO_SHORT 4
306 #define CDR_EXECFAILED_CMD_TOO_LONG 5
307 #define CDR_EXECFAILED_TARGETADDRTYPE_UNKNOWN 6
308 #define CDR_EXECFAILED_TARGETADDR_DOESNTEXIST 7
309 #define CDR_EXECFAILED_TARGETADDR_PORTCLOSED 8
310 #define CDR_EXECFAILED_LISTENERQUEUE_FULL 9
311 #define CDR_EXECFAILED_ILLEGAL_COMMAND 10
314 * must be sent after CDR_EXEC{OK|FAILED}
315 * CDR_EXEOK_BINDATA[1] bindatalen[1-4] bindata[bindatalen] */
316 #define CDR_BINDATA 3
319 * sending 2^32 credits per millisec means that credits the neighbor owns
320 * should be halfed after 1 minute
322 * ((x - 4294967295)/x) ^ 60000 = 0.5
323 * (x-4294967295)/x = 0.5**(1/60000)
324 * x/x - 4294967295/x = 0.5**(1/60000)
325 * 1 - 0.5**(1/60000) = 4294967295/x
326 * x = 4294967295 / (1 - 0.5**(1/60000))
328 #define CREDITS_TOTAL (1LL << 63)
332 /* result codes for rcv.c/proc_packet */
333 #define RC_DROP 0
334 #define RC_FINISHED 1
336 #define RC_RCV1_ANNOUNCE 2
337 #define RC_RCV1_KERNEL 3
338 #define RC_RCV1_CONN 4
340 struct htab_entry{
341 /* start of next element, *not* next htab_entry */
342 void *next;
345 struct htable{
346 struct htab_entry **htable;
347 __u32 htable_size;
348 __u32 cell_size;
349 __u32 num_elements;
351 int (*matches)(void *htentry, void *searcheditem);
352 __u32 key_offset;
353 __u32 entry_offset;
354 __u32 kref_offset;
357 struct resume_block{
358 struct list_head lh;
359 int in_queue;
362 struct announce_data{
363 struct kref ref;
365 struct list_head lh;
366 struct net_device *dev;
367 struct delayed_work announce_work;
368 struct announce *ann;
369 struct resume_block rb;
371 __u32 curr_announce_msg_offset;
372 __u64 scheduled_announce_timer;
375 struct ping_cookie{
376 unsigned long time;
377 __u32 cookie;
378 __u8 pongs; /* count of pongs for pings sent after this one */
381 #define NEIGHBOR_STATE_INITIAL 0
382 #define NEIGHBOR_STATE_ACTIVE 1
383 #define NEIGHBOR_STATE_STALLED 2
384 #define NEIGHBOR_STATE_KILLED 3
386 struct neighbor{
387 struct list_head nb_list;
389 struct kref ref;
391 struct net_device *dev;
392 char mac[MAX_ADDR_LEN];
394 char *addr;
395 __u16 addrlen;
397 struct delayed_work cmsg_timer;
398 struct mutex cmsg_lock;
399 struct list_head control_msgs_out;
401 * urgent messages; These are sent even if the neighbor state is not
402 * active. If the queue gets full, the oldest ones are dropped. It thus
403 * may only contain messages which are allowed to be dropped.
405 struct list_head ucontrol_msgs_out;
406 unsigned long timeout;
407 __u32 cmlength;
408 __u32 ucmlength;
410 atomic_t cmcnt; /* size of queue + retransmits */
411 atomic_t ucmcnt; /* size of queue only */
413 __u8 ping_all_conns;
414 __u8 max_cmsg_delay_sent;
416 /* see snd.c/qos_queue */
417 /* protected by cmsg_lock */
418 __u8 kp_allmsgs;
420 /* procected by queues_lock */
421 struct resume_block rb_kp;
422 struct resume_block rb_cr;
424 struct mutex pingcookie_lock;
425 unsigned long last_ping_time;
426 __u32 ping_intransit;
427 struct ping_cookie cookies[PING_COOKIES_PER_NEIGH];
428 __u32 lastcookie;
429 atomic_t latency; /* microsecs */
430 atomic_t max_remote_cmsg_delay; /* microsecs */
432 spinlock_t state_lock;
433 union {
434 __u64 last_state_change;/* initial state */
436 * last_roundtrip:
437 * time of the last sent packet which has been acked or
438 * otherwise responded to (e.g. pong)
440 unsigned long last_roundtrip;/* active/stalled state */
441 }state_time;
442 __u8 state;
443 __u16 ping_success;
445 struct delayed_work stalltimeout_timer;
446 __u8 str_timer_pending;
449 atomic_t kpacket_seqno;
450 atomic_t ooo_packets;
452 spinlock_t credits_lock;
453 unsigned long jiffies_credit_update;
454 unsigned long jiffies_credit_decay;
456 /* we only keep track on how much the other side may spend */
457 __u64 credits;
458 __u32 credits_fract;
459 /* credit rates are in credits/sec */
460 __u32 creditrate_initial;
461 __u64 creditrate_earning;
462 __u64 creditrate_spending;
465 * connecions which receive data from/send data to this node
466 * used when terminating all connections of a neighbor
468 struct mutex conn_list_lock;
469 struct list_head rcv_conn_list;
470 struct list_head snd_conn_list;
471 __u32 num_send_conns;
474 * used for ping_all conns, if not zero this is the next conn we need to
475 * ping, protected by conn_list_lock
477 struct conn *next_ping_conn;
478 __u32 ping_conns_remaining;
479 __u32 ping_conns_retrans_remaining;
480 __u32 pong_conns_expected;
481 unsigned long ping_conn_completed; /* jiffies */
484 * the timer has to be inited when adding the neighbor
485 * init_timer(struct timer_list * timer);
486 * add_timer(struct timer_list * timer);
488 spinlock_t retrans_lock;
489 struct delayed_work retrans_timer_conn;
490 struct delayed_work retrans_timer;
491 __u8 retrans_timer_conn_running;
492 __u8 retrans_timer_running;
494 struct list_head retrans_list;
495 struct list_head retrans_list_conn;
497 struct conn *firstboundconn;
500 struct cor_sched_data{
501 spinlock_t lock;
502 struct list_head conn_list;
503 struct sk_buff_head requeue_queue;
506 #define TYPE_BUF 0
507 #define TYPE_SKB 1
509 struct data_buf_item{
510 struct list_head buf_list;
512 union {
513 struct {
514 char *buf;
515 __u16 datalen;
516 __u16 buflen;
518 }buf;
520 struct sk_buff *skb;
521 }data;
523 __u8 type;
526 struct connlistener;
528 struct bindnode{
529 struct list_head lh;
530 struct connlistener *owner;
531 __be64 port;
534 #define SOCKSTATE_LISTENER 1
535 #define SOCKSTATE_CONN 2
537 struct sock_hdr {
538 /* The first member of connlistener/conn (see sock.c) */
539 __u8 sockstate;
542 struct connlistener {
543 /* The first member has to be the same as in conn (see sock.c) */
544 __u8 sockstate;
545 struct bindnode *bn;
546 struct mutex lock;
547 int queue_maxlen;
548 int queue_len;
549 struct list_head conn_queue;
550 wait_queue_head_t wait;
554 struct speedtracker{
555 __u64 speed;/* bytes*65536/jiffie */
556 unsigned long jiffies_last_update;
557 __u32 bytes_curr;
561 * There are 2 conn objects per bi-directional connection. They refer to each
562 * other with in the reversedir field. To distinguish them, the variables on
563 * the stack are usually called rconn and sconn. rconn refers to the conn object
564 * which has received a command. sconn is the other conn object.
566 struct conn{
567 /* The first member has to be the same as in connlistener (see sock.c)*/
568 __u8 sockstate;
570 #define SOURCE_NONE 0
571 #define SOURCE_IN 1
572 #define SOURCE_SOCK 2
574 #define TARGET_UNCONNECTED 0
575 #define TARGET_OUT 1
576 #define TARGET_SOCK 2
578 __u8 sourcetype:4,
579 targettype:4;
581 __u8 tos;
583 __u8 last_bufferstate:1,
584 in_credit_list:1;
587 * isreset values:
588 * 0... connection active
589 * 1... connection is about to be reset, target does not need to be
590 * notified
591 * 2... connection is reset
592 * 3... connection is reset + no pointers to "struct conn *reversedir"
593 * remaining except from this conn
595 atomic_t isreset;
597 struct list_head queue_list;
599 struct kref ref;
602 * locking order:
603 * 1) If both sides are SOCK, the side with source.sock.is_client == 1
604 * has to be locked first. This is needed for credits.
605 * 2) If one side is NONE/UNCONNECTED then the direction with
606 * TARGET_UNCONNECTED has to be locked first This is needed for
607 * changing source/targettype, credit flow and TARGET_UNCONNECTED
608 * generating responses.
609 * 3) If one side is SOCK and the other is IN/OUT, TARGET_SOCK has to be
610 * locked first.
611 * 4) If both sides are IN/OUT and the connection is not fully
612 * established, the side with has target.out.connid == 0 has to be
613 * locked first.
614 * 5) If data is forwarded, (both sides are IN/OUT), only one direction
615 * may be locked.
617 struct mutex rcv_lock;
619 unsigned long jiffies_credit_update;
620 struct list_head credit_list;
621 /* state */
622 __u64 credits;
623 /* credit rates per second, locked by credit_lock (in credit.c) */
624 __u64 crate_in;
625 __u32 crate_out;
627 * This is how much we *want* to forward, not how much we actually do.
628 * 2^31 == 100%
630 __u32 crate_forward;
632 union{
633 struct{
634 struct neighbor *nb;
635 /* list of all connections from this neighbor */
636 struct list_head nb_list;
638 struct sk_buff_head reorder_queue;
640 struct htab_entry htab_entry;
641 __u32 conn_id;
642 __u32 next_seqno;
643 __u32 ooo_packets;
645 atomic_t pong_awaiting;
647 /* credit rate */
648 __u16 decaytime;
649 __u8 decaytime_seqno;
651 __u32 window_seqnolimit_max;
652 __u32 window_seqnolimit_last;
654 struct list_head buffer_list;
656 __u32 buffer_init;
657 __u32 buffer_speed;
658 __u32 buffer_ata;
660 __u32 usage_init;
661 __u32 usage_speed;
662 __u32 usage_ata;
663 __u32 usage_reserve;
665 struct speedtracker st;
667 unsigned long jiffies_last_window_set;
668 }in;
670 struct{
671 struct list_head cl_list;
672 wait_queue_head_t wait;
673 struct socket *sock;
674 int flags;
676 __u32 crate;
677 __u32 alloclimit;
678 struct sock_buffertracker *sbt;
679 struct list_head delflush_list;
680 struct list_head alwait_list;
681 __u8 in_alwait_list;
682 __u8 delay_flush;
683 __u8 is_client;
684 __u32 wait_len;
685 }sock;
686 }source;
688 union{
689 struct{
690 __u32 paramlen;
691 __u32 cmdread;
692 __u16 cmd;
693 __u8 paramlen_read;
694 __u8 *cmdparams;
695 char paramlen_buf[4];
697 __u8 in_buffer_wait_list;
698 struct list_head buffer_wait_list;
699 }unconnected;
701 struct{
702 /* has to be first (because it is first in target
703 * kernel too)
705 struct neighbor *nb;
706 /* list of all connections to this neighbor */
707 struct list_head nb_list;
708 /* protected by nb->retrans_lock, sorted by seqno */
709 struct list_head retrans_list;
711 /* reverse conn_id lookup */
712 struct htab_entry htab_entry;
714 __u32 conn_id;
715 __u32 seqno_nextsend;
716 __u32 seqno_acked;
717 __u32 seqno_windowlimit;
719 struct resume_block rb;
721 __u16 decaytime_last;
722 __u8 decaytime_seqno;
723 __u8 decaytime_send_allowed;
724 }out;
726 struct{
727 wait_queue_head_t wait;
729 __u8 credituser;
730 }sock;
731 }target;
733 struct{
734 struct list_head items;
735 struct data_buf_item *lastread;
736 __u32 first_offset;
738 __u32 totalsize;
739 __u32 overhead;
740 __u32 read_remaining;
742 __u16 last_read_offset;
744 __u16 cpacket_buffer;/* including overhead */
745 }data_buf;
747 struct conn *reversedir;
750 /* inside skb->cb */
751 struct skb_procstate{
752 union{
753 struct{
754 struct work_struct work;
755 }rcv;
757 struct{
758 __u32 offset;
759 }announce;
761 struct{
762 __u32 seqno;
763 }rcv2;
764 }funcstate;
767 struct sock_buffertracker {
768 struct list_head lh;
770 uid_t uid;
771 __u64 usage;
773 struct list_head delflush_conns;
774 struct list_head waiting_conns;
776 struct kref ref;
780 /* common.c */
781 extern atomic_t num_conns;
783 extern __u8 __attribute__((const)) enc_log_64_11(__u32 window_bytes);
785 extern __u32 __attribute__((const)) dec_log_64_11(__u8 window);
787 extern __u16 __attribute__((const)) enc_log_300_24(__u64 value);
789 extern __u64 __attribute__((const)) dec_log_300_24(__u16 value);
791 extern __u64 __attribute__((const)) multiply_div(__u64 a, __u64 b, __u64 c);
793 extern char *htable_get(struct htable *ht, __u32 key, void *searcheditem);
795 extern int htable_delete(struct htable *ht, __u32 key, void *searcheditem,
796 void (*free) (struct kref *ref));
798 extern void htable_insert(struct htable *ht, char *newelement, __u32 key);
800 extern void htable_init(struct htable *ht, int (*matches)(void *htentry,
801 void *searcheditem), __u32 entry_offset,
802 __u32 kref_offset);
804 extern struct conn *get_conn_reverse(struct neighbor *nb, __u32 conn_id);
806 extern void insert_reverse_connid(struct conn *rconn);
808 extern struct conn *get_conn(__u32 conn_id);
810 extern void free_conn(struct kref *ref);
812 extern int conn_init_out(struct conn *rconn, struct neighbor *nb);
814 extern void conn_init_sock_source(struct conn *conn);
816 extern void conn_init_sock_target(struct conn *conn);
818 extern void close_port(struct connlistener *listener);
820 extern struct connlistener *open_port(__be64 port);
822 extern int connect_port(struct conn *rconn, __be64 port);
824 extern int connect_neigh(struct conn *rconn,
825 __u16 addrtypelen, __u8 *addrtype,
826 __u16 addrlen, __u8 *addr);
828 extern struct conn* alloc_conn(gfp_t allocflags);
830 extern void reset_ping(struct conn *rconn);
832 extern void reset_conn(struct conn *conn);
834 /* credits.c */
835 extern __u32 creditrate_initial(void);
837 extern int refresh_conn_credits(struct conn *conn, int fromperiodic,
838 int locked);
840 extern void set_creditrate_initial(struct neighbor *nb, __u32 debitrate);
842 extern void set_conn_in_decaytime(struct conn *rconn, __u8 decaytime_seqno,
843 __u16 decaytime);
845 extern void connreset_credits(struct conn *conn);
847 extern void __init credits_init(void);
849 /* neighbor.c */
850 extern void neighbor_free(struct kref *ref);
852 extern struct neighbor *get_neigh_by_mac(struct sk_buff *skb);
854 extern struct neighbor *find_neigh(__u16 addrtypelen, __u8 *addrtype,
855 __u16 addrlen, __u8 *addr);
857 extern __u32 generate_neigh_list(char *buf, __u32 buflen, __u32 limit,
858 __u32 offset);
860 extern int get_neigh_state(struct neighbor *nb);
862 extern void ping_resp(struct neighbor *nb, __u32 cookie, __u32 respdelay);
864 extern __u32 add_ping_req(struct neighbor *nb);
866 extern void unadd_ping_req(struct neighbor *nb, __u32 cookie);
868 extern int time_to_send_ping(struct neighbor *nb);
870 extern int force_ping(struct neighbor *nb);
872 extern void rcv_announce(struct sk_buff *skb);
874 extern int send_announce_qos(struct announce_data *ann);
876 extern void announce_data_free(struct kref *ref);
878 extern int __init cor_neighbor_init(void);
880 /* rcv.c */
881 extern __u8 get_window(struct conn *rconn);
883 extern void reset_bufferusage(struct conn *conn);
885 extern void refresh_speedstat(struct conn *rconn, __u32 written);
887 extern void drain_ooo_queue(struct conn *rconn);
889 extern void conn_rcv_buildskb(char *data, __u32 datalen, __u32 conn_id,
890 __u32 seqno);
892 extern int __init cor_rcv_init(void);
894 /* kpacket_parse.c */
895 extern void kernel_packet(struct neighbor *nb, struct sk_buff *skb, __u32 seqno);
897 /* kpacket_gen.c */
898 extern void schedule_controlmsg_timerfunc(struct neighbor *nb);
900 struct control_msg_out;
902 #define ACM_PRIORITY_LOW 1
903 #define ACM_PRIORITY_MED 2
904 #define ACM_PRIORITY_HIGH 3
906 extern int may_alloc_control_msg(struct neighbor *nb, int priority);
908 extern struct control_msg_out *alloc_control_msg(struct neighbor *nb,
909 int priority);
911 extern void free_control_msg(struct control_msg_out *cm);
913 extern void retransmit_timerfunc(struct work_struct *work);
915 extern void kern_ack_rcvd(struct neighbor *nb, __u32 seqno);
917 extern int send_messages(struct neighbor *nb, int allmsgs, int resume);
919 extern void send_pong(struct neighbor *nb,
920 __u32 cookie);
922 extern void send_reset_conn(struct control_msg_out *cm, __u32 conn_id);
924 extern void send_ack(struct neighbor *nb,
925 __u32 seqno);
927 extern void send_ack_conn(struct control_msg_out *cm, struct conn *rconn,
928 __u32 conn_id, __u32 seqno);
930 extern void send_ack_conn_ooo(struct control_msg_out *cm, struct conn *rconn,
931 __u32 conn_id, __u32 seqno_ooo, __u32 length);
933 extern void send_decaytime(struct conn *rconn, int force, __u16 decaytime);
935 extern void send_connect_success(struct control_msg_out *cm, __u32 rcvd_conn_id,
936 __u32 gen_conn_id, __u32 init_seqno, struct conn *rconn);
938 extern void send_connect_nb(struct control_msg_out *cm, __u32 conn_id,
939 __u32 init_seqno, struct conn *sconn);
941 extern void send_conndata(struct control_msg_out *cm, __u32 conn_id,
942 __u32 seqno, char *data_orig, char *data, __u32 datalen);
944 extern void send_connid_unknown(struct control_msg_out *cm, __u32 conn_id);
946 extern void send_ping_all_conns(struct neighbor *nb);
948 extern void __init cor_kgen_init(void);
950 /* cpacket_parse.c */
951 extern void free_cpacket_buffer(__s32 amount);
953 extern void connreset_cpacket_buffer(struct conn *rconn);
955 extern int encode_len(char *buf, int buflen, __u32 len);
957 extern int decode_len(char *buf, int buflen, __u32 *len);
959 extern void parse(struct conn *rconn, int fromresume);
961 extern int __init cor_cpacket_init(void);
963 /* snd.c */
964 extern int destroy_queue(struct net_device *dev);
966 extern int create_queue(struct net_device *dev);
968 #define QOS_CALLER_KPACKET 0
969 #define QOS_CALLER_CONN_RETRANS 1
970 #define QOS_CALLER_ANNOUNCE 2
971 #define QOS_CALLER_CONN 3
973 extern void qos_enqueue(struct net_device *dev, struct resume_block *rb,
974 int caller);
976 extern void qos_remove_conn(struct conn *rconn);
978 extern struct sk_buff *create_packet(struct neighbor *nb, int size,
979 gfp_t alloc_flags, __u32 conn_id, __u32 seqno);
981 extern void cancel_retrans(struct conn *rconn);
983 extern void retransmit_conn_timerfunc(struct work_struct *work);
985 extern void conn_ack_ooo_rcvd(struct conn *rconn, __u32 seqno_ooo,
986 __u32 length);
988 extern void conn_ack_rcvd(struct conn *rconn, __u32 seqno, int setwindow,
989 __u8 window);
991 #define RC_FLUSH_CONN_OUT_OK 0
992 #define RC_FLUSH_CONN_OUT_OK_SENT 1
993 #define RC_FLUSH_CONN_OUT_CONG 2
994 #define RC_FLUSH_CONN_OUT_CREDITS 3
995 #define RC_FLUSH_CONN_OUT_OOM 4
996 extern int flush_out(struct conn *rconn, int fromqos, __u32 creditsperbyte);
998 extern int __init cor_snd_init(void);
1000 /* forward.c */
1001 extern void databuf_pull(struct conn *conn, char *dst, int len);
1003 extern size_t databuf_pulluser(struct conn *sconn, struct msghdr *msg);
1005 extern void databuf_unpull(struct conn *conn, __u32 bytes);
1007 extern void databuf_pullold(struct conn *conn, __u32 startpos, char *dst,
1008 int len);
1010 extern void databuf_ack(struct conn *rconn, __u32 pos);
1012 extern void databuf_ackread(struct conn *rconn);
1014 extern void flush_buf(struct conn *rconn);
1016 extern void reset_seqno(struct conn *conn, __u32 initseqno);
1018 extern void databuf_free(struct conn *conn);
1020 extern void databuf_init(struct conn *conn);
1022 __s64 receive_userbuf(struct conn *rconn, struct msghdr *msg, __u32 maxcpy,
1023 __u32 maxusage);
1025 extern void receive_cpacketresp(struct conn *rconn, char *buf, int len);
1027 extern int receive_skb(struct conn *rconn, struct sk_buff *skb);
1029 extern void wake_sender(struct conn *rconn);
1031 extern void __init forward_init(void);
1033 /* sock.c */
1034 extern struct mutex sock_bufferlimits_lock;
1036 extern void free_sbt(struct kref *ref);
1038 extern void unreserve_sock_buffer(struct conn *conn);
1041 static inline struct skb_procstate *skb_pstate(struct sk_buff *skb)
1043 return (struct skb_procstate *) &(skb->cb[0]);
1046 static inline struct sk_buff *skb_from_pstate(struct skb_procstate *ps)
1048 return (struct sk_buff *) (((char *)ps) - offsetof(struct sk_buff,cb));
1052 static inline __u32 mss(struct neighbor *nb)
1054 return nb->dev->mtu - LL_RESERVED_SPACE(nb->dev) - 9;
1058 static inline void put_u64(char *dst, __u64 value, int convbo)
1060 char *p_value = (char *) &value;
1062 if (convbo)
1063 value = cpu_to_be64(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];
1069 dst[4] = p_value[4];
1070 dst[5] = p_value[5];
1071 dst[6] = p_value[6];
1072 dst[7] = p_value[7];
1075 static inline void put_u32(char *dst, __u32 value, int convbo)
1077 char *p_value = (char *) &value;
1079 if (convbo)
1080 value = cpu_to_be32(value);
1082 dst[0] = p_value[0];
1083 dst[1] = p_value[1];
1084 dst[2] = p_value[2];
1085 dst[3] = p_value[3];
1088 static inline void put_u16(char *dst, __u16 value, int convbo)
1090 char *p_value = (char *) &value;
1092 if (convbo)
1093 value = cpu_to_be16(value);
1095 dst[0] = p_value[0];
1096 dst[1] = p_value[1];
1099 static inline char *cor_pull_skb(struct sk_buff *skb, unsigned int len)
1101 char *ptr = skb_pull(skb, len);
1103 if(unlikely(ptr == 0))
1104 return 0;
1106 return ptr - len;
1109 #define S64_MAX 9223372036854775807LL
1110 #define S64_MIN (1LL << 63)