per conn neighbor stall timeout removal
[cor_2_6_31.git] / net / cor / cor.h
blobc4d2075408f0ad4f0d87a4d78955eb50ce694e99
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] 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
106 #define KP_ACK_CONN 5
107 #define KP_ACK_CONN_OOO 6
110 * NOTE on connection ids:
111 * connection ids + init seqnos we send are used for the receive channel
112 * connection ids + init seqnos we receive are used for the send channel
116 * incoming connection
117 * KP_CONNECT[1] conn_id[4] init_seqno[4] window[1]
119 #define KP_CONNECT 7
122 * incoming connection successful,
123 * the first conn_id is the same as previously sent/received in KP_CONNECT
124 * the second conn_id is generated by us and used for the other direction
125 * KP_CONNECT_SUCCESS[1] conn_id[4] conn_id[4] init_seqno[4] window[1]
127 #define KP_CONNECT_SUCCESS 8
129 /* KP_CONN_DATA[1] conn_id[4] seqno[4] length[2] data[length] */
130 #define KP_CONN_DATA 9
133 * KP_PING_CONN[1] conn_id[4]
135 * This is for querying the status of an open connection. The response is either
136 * KP_ACK_CONN or CONNID_UNKNOWN
138 #define KP_PING_CONN 10
141 * { KP_RESET_CONN[1] conn_id[4] }
142 * We send this, if there is an established connection we want to close.
144 #define KP_RESET_CONN 11
147 * KP_CONNID_UNKNOWN[1] sent_conn_id[4]
148 * We send this, if we receive an invalid conn_id
150 #define KP_CONNID_UNKNOWN 12
153 * KP_PING_ALL_CONNS[1]
154 * We send this, if we we lost a conn, but could not send reset_conn and
155 * connid_unknown
157 #define KP_PING_ALL_CONNS 13
160 * KP_SET_MAX_CMSG_DELAY[1] delay[4]
161 * Sent after connecting and at any change
162 * delay in specifies in microsecs
164 #define KP_SET_MAX_CMSG_DELAY 14
167 * KP_SET_CREDITS[1] credits[8] rate_initial[4] rate_earning[4] rate_spending[4]
169 #define KP_SET_CREDITS 15
172 * KP_SET_CONN_CREDITS[1] conn_id[4] credit_rate[4]
174 #define KP_SET_CONN_CREDITS 16
178 * Connection data which in interpreted when connection has no target yet
179 * These commands are sent by the end node.
181 * Format:
182 * cmd[2] length[1-4] parameter[length]
183 * unrecogniced commands are ignored
184 * parameters which are longer than expected are ignored as well
187 /* outgoing connection: CD_CONNECT_NB[2] length[1-4]
188 * addrtypelen[1-4] addrlen[1-4] addrtype[addrtypelen] addr[addrlen] */
189 #define CD_CONNECT_NB 1
191 /* connection to local open part: CD_CONNECT_PORT[2] length[1-4] port[8] */
192 #define CD_CONNECT_PORT 2
195 * CD_LIST_NEIGH sends CDR_BINDATA if the command was successful. The response
196 * format is:
198 * totalneighs[1-4] response_rows[1-4]
199 * for every row:
200 * numaddr[1-4] (addrtypelen[1-4] addrlen[1-4] addrtype[addrtypelen]
201 * addr[addrlen])[numaddr]
203 * Neighbors have to be sorted by uptime, new neighbors first. This is so that
204 * the routing daemon can easily find out whether there are new neighbors. It
205 * only needs to send a query with offset 0. If the totalneighs stays the same
206 * while new were added, a connection to another neighbor was lost.
209 /* list connected neighbors: CD_LIST_NEIGH[2] length[1-4] limit[1-4]
210 * offset[1-4] */
211 #define CD_LIST_NEIGH 3
215 * CD_SET_TOS[2] length[1-4] forward_tos[1] backward_tos[1]
216 * Only 2 bits of the tos flags are used, the highers 6 bits are ignored.
218 #define CD_SET_TOS 4
220 #define TOS_NORMAL 0
221 #define TOS_LATENCY 1
222 #define TOS_THROUGHPUT 2
223 #define TOS_PRIVACY 3
228 * Connection data response
229 * Format is the same as with connection data
233 * CDR_EXECOK[1]
235 #define CDR_EXECOK 1
238 * CDR_EXECFAILED[1] reasoncode[2]
239 * reasontextlength[1-4] reasontext[reasontextlength]
240 * reasontextlength may be 0
242 #define CDR_EXECFAILED 2
243 #define CDR_EXECFAILED_UNKNOWN_COMMAND 1
244 #define CDR_EXECFAILED_PERMISSION_DENIED 2
245 #define CDR_EXECFAILED_TEMPORARILY_OUT_OF_RESSOURCES 3
246 #define CDR_EXECFAILED_CMD_TOO_SHORT 4
247 #define CDR_EXECFAILED_CMD_TOO_LONG 5
248 #define CDR_EXECFAILED_TARGETADDRTYPE_UNKNOWN 6
249 #define CDR_EXECFAILED_TARGETADDR_DOESNTEXIST 7
250 #define CDR_EXECFAILED_TARGETADDR_PORTCLOSED 8
251 #define CDR_EXECFAILED_LISTENERQUEUE_FULL 9
252 #define CDR_EXECFAILED_ILLEGAL_COMMAND 10
255 * must be sent after CDR_EXEC{OK|FAILED}
256 * CDR_EXEOK_BINDATA[1] bindatalen[1-4] bindata[bindatalen] */
257 #define CDR_BINDATA 3
260 /* result codes for rcv.c/proc_packet */
261 #define RC_DROP 0
262 #define RC_FINISHED 1
264 #define RC_RCV1_ANNOUNCE 2
265 #define RC_RCV1_KERNEL 3
266 #define RC_RCV1_CONN 4
268 struct htab_entry{
269 /* start of next element, *not* next htab_entry */
270 void *next;
273 struct htable{
274 struct htab_entry **htable;
275 __u32 htable_size;
276 __u32 cell_size;
277 __u32 num_elements;
279 int (*matches)(void *htentry, void *searcheditem);
280 __u32 key_offset;
281 __u32 entry_offset;
282 __u32 kref_offset;
285 struct resume_block{
286 struct list_head lh;
287 int in_queue;
290 struct announce_data{
291 struct kref ref;
293 struct list_head lh;
294 struct net_device *dev;
295 struct delayed_work announce_work;
296 struct announce *ann;
297 struct resume_block rb;
299 __u32 curr_announce_msg_offset;
300 __u64 scheduled_announce_timer;
303 struct ping_cookie{
304 unsigned long time;
305 __u32 cookie;
306 __u8 pongs; /* count of pongs for pings sent after this one */
309 #define NEIGHBOR_STATE_INITIAL 0
310 #define NEIGHBOR_STATE_ACTIVE 1
311 #define NEIGHBOR_STATE_STALLED 2
312 #define NEIGHBOR_STATE_KILLED 3
314 struct neighbor{
315 struct list_head nb_list;
317 struct kref ref;
319 struct net_device *dev;
320 char mac[MAX_ADDR_LEN];
322 char *addr;
323 __u16 addrlen;
325 struct delayed_work cmsg_timer;
326 struct mutex cmsg_lock;
327 struct list_head control_msgs_out;
329 * urgent messages; These are sent even if the neighbor state is not
330 * active. If the queue gets full, the oldest ones are dropped. It thus
331 * may only contain messages which are allowed to be dropped.
333 struct list_head ucontrol_msgs_out;
334 unsigned long timeout;
335 __u32 cmlength;
336 __u32 ucmlength;
338 atomic_t cmcnt; /* size of queue + retransmits */
339 atomic_t ucmcnt; /* size of queue only */
341 __u8 ping_all_conns;
342 __u8 send_credits;
343 __u8 max_cmsg_delay_sent;
345 /* see snd.c/qos_queue */
346 /* protected by cmsg_lock */
347 __u8 kp_allmsgs;
349 /* procected by queues_lock */
350 struct resume_block rb_kp;
351 struct resume_block rb_cr;
353 struct mutex pingcookie_lock;
354 unsigned long last_ping_time;
355 __u32 ping_intransit;
356 struct ping_cookie cookies[PING_COOKIES_PER_NEIGH];
357 __u32 lastcookie;
358 atomic_t latency; /* microsecs */
359 atomic_t max_remote_cmsg_delay; /* microsecs */
361 spinlock_t state_lock;
362 union {
363 __u64 last_state_change;/* initial state */
365 * last_roundtrip:
366 * time of the last sent packet which has been acked or
367 * otherwise responded to (e.g. pong)
369 unsigned long last_roundtrip;/* active/stalled state */
370 }state_time;
371 __u8 state;
372 __u16 ping_success;
374 struct delayed_work stalltimeout_timer;
375 __u8 str_timer_pending;
378 atomic_t kpacket_seqno;
379 atomic_t ooo_packets;
381 spinlock_t credits_lock;
382 long jiffies_credit_update;
384 /* all cretid rates are in credits/ms */
385 __u64 credits; /* how much we can spend */
386 __u32 credits_fract;
387 __u64 credits_diff; /* diff between the neighbor's and our calc */
388 __u32 credits_diff_fract;
389 __s32 creditrate_initial;
390 __u32 creditrate_earning;
391 __u32 creditrate_spending;
392 __u32 creditrate_spending_expected;
394 __s32 creditrate_spending_diff;
396 __u64 debits; /* how much the other side can spend */
397 __u32 debits_fract;
398 __s32 debitrate_initial;
399 __s32 debitrate_initial_adj;
400 __u32 debitrate_earning;
401 __u32 debitrate_spending;
404 * connecions which receive data from/send data to this node
405 * used when terminating all connections of a neighbor
407 struct mutex conn_list_lock;
408 struct list_head rcv_conn_list;
409 struct list_head snd_conn_list;
410 __u32 num_send_conns;
413 * used for ping_all conns, if not zero this is the next conn we need to
414 * ping, protected by conn_list_lock
416 struct conn *next_ping_conn;
417 __u32 ping_conns_remaining;
418 __u32 ping_conns_retrans_remaining;
419 __u32 pong_conns_expected;
420 unsigned long ping_conn_completed; /* jiffies */
423 * the timer has to be inited when adding the neighbor
424 * init_timer(struct timer_list * timer);
425 * add_timer(struct timer_list * timer);
427 spinlock_t retrans_lock;
428 struct delayed_work retrans_timer_conn;
429 struct delayed_work retrans_timer;
430 __u8 retrans_timer_conn_running;
431 __u8 retrans_timer_running;
433 struct list_head retrans_list;
434 struct list_head retrans_list_conn;
436 struct conn *firstboundconn;
439 struct cor_sched_data{
440 spinlock_t lock;
441 struct list_head conn_list;
442 struct sk_buff_head requeue_queue;
445 #define TYPE_BUF 0
446 #define TYPE_SKB 1
448 struct data_buf_item{
449 struct list_head buf_list;
451 union {
452 struct {
453 char *buf;
454 __u16 datalen;
455 __u16 buflen;
457 }buf;
459 struct sk_buff *skb;
460 }data;
462 __u8 type;
465 struct connlistener;
467 struct bindnode{
468 struct list_head lh;
469 struct connlistener *owner;
470 __be64 port;
473 #define SOCKSTATE_LISTENER 1
474 #define SOCKSTATE_CONN 2
476 struct sock_hdr {
477 /* The first member of connlistener/conn (see sock.c) */
478 __u8 sockstate;
481 struct connlistener {
482 /* The first member has to be the same as in conn (see sock.c) */
483 __u8 sockstate;
484 struct bindnode *bn;
485 struct mutex lock;
486 int queue_maxlen;
487 int queue_len;
488 struct list_head conn_queue;
489 wait_queue_head_t wait;
493 struct speedtracker{
494 __u64 speed;/* bytes*65536/jiffie */
495 unsigned long jiffies_last_update;
496 __u32 bytes_curr;
500 * There are 2 conn objects per bi-directional connection. They refer to each
501 * other with in the reversedir field. To distinguish them, the variables on
502 * the stack are usually called rconn and sconn. rconn refers to the conn object
503 * which has received a command. sconn is the other conn object.
505 struct conn{
506 /* The first member has to be the same as in connlistener (see sock.c)*/
507 __u8 sockstate;
509 #define SOURCE_NONE 0
510 #define SOURCE_IN 1
511 #define SOURCE_SOCK 2
513 #define TARGET_UNCONNECTED 0
514 #define TARGET_OUT 1
515 #define TARGET_SOCK 2
517 __u8 sourcetype:4,
518 targettype:4;
520 __u8 tos;
522 __u8 last_bufferstate:1,
523 in_credit_list:1;
526 * isreset values:
527 * 0... connection active
528 * 1... connection is about to be reset, target does not need to be
529 * notified
530 * 2... connection is reset
531 * 3... connection is reset + no pointers to "struct conn *reversedir"
532 * remaining except from this conn
534 atomic_t isreset;
536 struct list_head queue_list;
538 struct kref ref;
541 * locking order:
542 * If one side is SOCK or NONE/UNCONNECTED and both directions
543 * need to be locked, the direction with TARGET_UNCONNECTED or
544 * TARGET_SOCK has to be locked first, the direction with
545 * SOURCE_NONE or SOURCE_SOCK afterwards. If one side is TARGET_SOCK
546 * and the other is TARGET_UNCONNECTED, TARGET_SOCK needs to be locked
547 * first. This is needed for changing source/targettype, credit flow
548 * and TARGET_UNCONNECTED generating responses.
549 * If data is forwarded, (both sides are IN/OUT), only one direction
550 * may be locked.
552 struct mutex rcv_lock;
554 unsigned long jiffies_credit_update;
555 struct list_head credit_list;
556 /* state */
557 __s64 credits;
558 __u32 credits_fract;
559 /* credit rates, locked by credit_lock (in credit.c) */
560 __u32 sender_crate;
561 __u32 recp_crate;
563 * This is how much we *want* to forward, but how much we actually do.
564 * 2^32 == 100%
566 __u32 crate_forward;
568 union{
569 struct{
570 struct neighbor *nb;
571 /* list of all connections from this neighbor */
572 struct list_head nb_list;
574 struct sk_buff_head reorder_queue;
576 struct htab_entry htab_entry;
577 __u32 conn_id;
578 __u32 next_seqno;
579 __u32 ooo_packets;
581 atomic_t pong_awaiting;
583 /* credit rate */
584 __u32 crate_in_raw;
586 __u32 window_seqnolimit_max;
587 __u32 window_seqnolimit_last;
589 struct list_head buffer_list;
591 __u32 buffer_init;
592 __u32 buffer_speed;
593 __u32 buffer_ata;
595 __u32 usage_init;
596 __u32 usage_speed;
597 __u32 usage_ata;
598 __u32 usage_reserve;
600 struct speedtracker st;
602 unsigned long jiffies_last_window_set;
603 }in;
605 struct{
606 struct list_head cl_list;
607 wait_queue_head_t wait;
608 struct socket *sock;
609 int flags;
611 __u32 crate;
612 __u32 alloclimit;
613 struct sock_buffertracker *sbt;
614 struct list_head delflush_list;
615 struct list_head alwait_list;
616 __u8 in_alwait_list;
617 __u8 delay_flush;
618 __u32 wait_len;
619 }sock;
620 }source;
622 union{
623 struct{
624 __u32 paramlen;
625 __u32 cmdread;
626 __u16 cmd;
627 __u8 paramlen_read;
628 __u8 *cmdparams;
629 char paramlen_buf[4];
631 __u8 in_buffer_wait_list;
632 struct list_head buffer_wait_list;
633 }unconnected;
635 struct{
636 /* has to be first (because it is first in target
637 * kernel too)
639 struct neighbor *nb;
640 /* list of all connections to this neighbor */
641 struct list_head nb_list;
642 /* protected by nb->retrans_lock, sorted by seqno */
643 struct list_head retrans_list;
645 /* reverse conn_id lookup */
646 struct htab_entry htab_entry;
648 __u32 conn_id;
649 __u32 seqno_nextsend;
650 __u32 seqno_acked;
651 __u32 seqno_windowlimit;
652 __u32 kp_windowsetseqno;
654 struct resume_block rb;
656 /* credit rate */
657 long jiffies_crate_send;
658 __u32 crate_out_raw;
659 }out;
661 struct{
662 wait_queue_head_t wait;
664 __u8 credituser;
665 }sock;
666 }target;
668 struct{
669 struct list_head items;
670 struct data_buf_item *lastread;
671 __u32 first_offset;
673 __u32 totalsize;
674 __u32 overhead;
675 __u32 read_remaining;
677 __u16 last_read_offset;
679 __u16 cpacket_buffer;/* including overhead */
680 }data_buf;
682 struct conn *reversedir;
685 /* inside skb->cb */
686 struct skb_procstate{
687 union{
688 struct{
689 struct work_struct work;
690 }rcv;
692 struct{
693 __u32 offset;
694 }announce;
696 struct{
697 __u32 seqno;
698 }rcv2;
699 }funcstate;
702 struct sock_buffertracker {
703 struct list_head lh;
705 uid_t uid;
706 __u64 usage;
708 struct list_head delflush_conns;
709 struct list_head waiting_conns;
711 struct kref ref;
715 /* common.c */
716 extern atomic_t num_conns;
718 extern __u8 enc_window(__u32 window_bytes);
720 extern __u32 dec_window(__u8 window);
722 extern char *htable_get(struct htable *ht, __u32 key, void *searcheditem);
724 extern int htable_delete(struct htable *ht, __u32 key, void *searcheditem,
725 void (*free) (struct kref *ref));
727 extern void htable_insert(struct htable *ht, char *newelement, __u32 key);
729 extern void htable_init(struct htable *ht, int (*matches)(void *htentry,
730 void *searcheditem), __u32 entry_offset,
731 __u32 kref_offset);
733 extern struct conn *get_conn_reverse(struct neighbor *nb, __u32 conn_id);
735 extern void insert_reverse_connid(struct conn *rconn);
737 extern struct conn *get_conn(__u32 conn_id);
739 extern void free_conn(struct kref *ref);
741 extern int conn_init_out(struct conn *rconn, struct neighbor *nb);
743 extern void conn_init_sock_source(struct conn *conn);
745 extern void conn_init_sock_target(struct conn *conn);
747 extern void close_port(struct connlistener *listener);
749 extern struct connlistener *open_port(__be64 port);
751 extern int connect_port(struct conn *rconn, __be64 port);
753 extern int connect_neigh(struct conn *rconn,
754 __u16 addrtypelen, __u8 *addrtype,
755 __u16 addrlen, __u8 *addr);
757 extern struct conn* alloc_conn(gfp_t allocflags);
759 extern void reset_ping(struct conn *rconn);
761 extern void reset_conn(struct conn *conn);
763 /* credits.c */
764 extern int refresh_credits_state(struct neighbor *nb);
766 extern void check_credit_state(struct neighbor *nb);
768 extern int debit_adj_needed(struct neighbor *nb);
770 extern int refresh_conn_credits(struct conn *conn, int fromperiodic);
772 extern void set_credits(struct neighbor *nb, __u64 credits,
773 __s32 creditrate_initial, __u32 creditrate_earning,
774 __u32 creditrate_spending);
776 extern void set_debitrate_initial(struct neighbor *nb, __u32 debitrate);
778 extern void set_conn_in_crate(struct conn *rconn, __u32 crate_in);
780 extern void connreset_credits(struct conn *conn);
782 extern void credits_init(void);
784 /* neighbor.c */
785 extern void neighbor_free(struct kref *ref);
787 extern struct neighbor *get_neigh_by_mac(struct sk_buff *skb);
789 extern struct neighbor *find_neigh(__u16 addrtypelen, __u8 *addrtype,
790 __u16 addrlen, __u8 *addr);
792 extern __u32 generate_neigh_list(char *buf, __u32 buflen, __u32 limit,
793 __u32 offset);
795 extern int get_neigh_state(struct neighbor *nb);
797 extern void ping_resp(struct neighbor *nb, __u32 cookie, __u32 respdelay);
799 extern __u32 add_ping_req(struct neighbor *nb);
801 extern void unadd_ping_req(struct neighbor *nb, __u32 cookie);
803 extern int time_to_send_ping(struct neighbor *nb);
805 extern int force_ping(struct neighbor *nb);
807 extern void rcv_announce(struct sk_buff *skb);
809 extern int send_announce_qos(struct announce_data *ann);
811 extern void announce_data_free(struct kref *ref);
813 extern int __init cor_neighbor_init(void);
815 /* rcv.c */
816 extern __u8 get_window(struct conn *rconn);
818 extern void reset_bufferusage(struct conn *conn);
820 extern void refresh_speedstat(struct conn *rconn, __u32 written);
822 extern void drain_ooo_queue(struct conn *rconn);
824 extern void conn_rcv_buildskb(char *data, __u32 datalen, __u32 conn_id,
825 __u32 seqno);
827 extern int __init cor_rcv_init(void);
829 /* kpacket_parse.c */
830 extern void kernel_packet(struct neighbor *nb, struct sk_buff *skb, __u32 seqno);
832 /* kpacket_gen.c */
833 extern void schedule_controlmsg_timerfunc(struct neighbor *nb);
835 struct control_msg_out;
837 #define ACM_PRIORITY_LOW 1
838 #define ACM_PRIORITY_MED 2
839 #define ACM_PRIORITY_HIGH 3
841 extern int may_alloc_control_msg(struct neighbor *nb, int priority);
843 extern struct control_msg_out *alloc_control_msg(struct neighbor *nb,
844 int priority);
846 extern void free_control_msg(struct control_msg_out *cm);
848 extern void retransmit_timerfunc(struct work_struct *work);
850 extern void kern_ack_rcvd(struct neighbor *nb, __u32 seqno);
852 extern int send_messages(struct neighbor *nb, int allmsgs, int resume);
854 extern void send_pong(struct neighbor *nb,
855 __u32 cookie);
857 extern void send_reset_conn(struct control_msg_out *cm, __u32 conn_id);
859 extern void send_ack(struct neighbor *nb,
860 __u32 seqno);
862 extern void send_ack_conn(struct control_msg_out *cm, struct conn *rconn,
863 __u32 conn_id, __u32 seqno);
865 extern void send_ack_conn_ooo(struct control_msg_out *cm, struct conn *rconn,
866 __u32 conn_id, __u32 seqno, __u32 seqno_ooo, __u32 length);
868 extern void send_connect_success(struct control_msg_out *cm, __u32 rcvd_conn_id,
869 __u32 gen_conn_id, __u32 init_seqno, struct conn *rconn);
871 extern void send_connect_nb(struct control_msg_out *cm, __u32 conn_id,
872 __u32 init_seqno, struct conn *sconn);
874 extern void send_conndata(struct control_msg_out *cm, __u32 conn_id,
875 __u32 seqno, char *data_orig, char *data, __u32 datalen);
877 extern void send_ping_conn(struct control_msg_out *cm, __u32 conn_id);
879 extern void send_connid_unknown(struct control_msg_out *cm, __u32 conn_id);
881 extern void send_ping_all_conns(struct neighbor *nb);
883 extern void send_credits(struct neighbor *nb);
885 extern void cor_kgen_init(void);
887 /* cpacket_parse.c */
888 extern void free_cpacket_buffer(__s32 amount);
890 extern void connreset_cpacket_buffer(struct conn *rconn);
892 extern int encode_len(char *buf, int buflen, __u32 len);
894 extern int decode_len(char *buf, int buflen, __u32 *len);
896 extern void parse(struct conn *rconn, int fromresume);
898 extern int __init cor_cpacket_init(void);
900 /* snd.c */
901 extern int destroy_queue(struct net_device *dev);
903 extern int create_queue(struct net_device *dev);
905 #define QOS_CALLER_KPACKET 0
906 #define QOS_CALLER_CONN_RETRANS 1
907 #define QOS_CALLER_ANNOUNCE 2
908 #define QOS_CALLER_CONN 3
910 extern void qos_enqueue(struct net_device *dev, struct resume_block *rb,
911 int caller);
913 extern void qos_remove_conn(struct conn *rconn);
915 extern struct sk_buff *create_packet(struct neighbor *nb, int size,
916 gfp_t alloc_flags, __u32 conn_id, __u32 seqno);
918 extern void cancel_retrans(struct conn *rconn);
920 extern void retransmit_conn_timerfunc(struct work_struct *work);
922 extern void conn_ack_rcvd(__u32 kpacket_seqno, struct conn *rconn, __u32 seqno,
923 __u8 window, __u32 seqno_ooo, __u32 length);
925 #define RC_FLUSH_CONN_OUT_OK 0
926 #define RC_FLUSH_CONN_OUT_OK_SENT 1
927 #define RC_FLUSH_CONN_OUT_CONG 2
928 #define RC_FLUSH_CONN_OUT_CREDITS 3
929 #define RC_FLUSH_CONN_OUT_OOM 4
930 extern int flush_out(struct conn *rconn, int fromqos, __u32 creditsperbyte);
932 extern int __init cor_snd_init(void);
934 /* forward.c */
935 extern void databuf_pull(struct conn *conn, char *dst, int len);
937 extern size_t databuf_pulluser(struct conn *sconn, struct msghdr *msg);
939 extern void databuf_unpull(struct conn *conn, __u32 bytes);
941 extern void databuf_pullold(struct conn *conn, __u32 startpos, char *dst,
942 int len);
944 extern void databuf_ack(struct conn *rconn, __u32 pos);
946 extern void databuf_ackread(struct conn *rconn);
948 extern void flush_buf(struct conn *rconn);
950 extern void reset_seqno(struct conn *conn, __u32 initseqno);
952 extern void databuf_free(struct conn *conn);
954 extern void databuf_init(struct conn *conn);
956 __s64 receive_userbuf(struct conn *rconn, struct msghdr *msg, __u32 maxcpy,
957 __u32 maxusage);
959 extern void receive_cpacketresp(struct conn *rconn, char *buf, int len);
961 extern int receive_skb(struct conn *rconn, struct sk_buff *skb);
963 extern void wake_sender(struct conn *rconn);
965 extern void forward_init(void);
967 /* sock.c */
968 extern struct mutex sock_bufferlimits_lock;
970 extern void free_sbt(struct kref *ref);
972 extern void unreserve_sock_buffer(struct conn *conn);
975 static inline struct skb_procstate *skb_pstate(struct sk_buff *skb)
977 return (struct skb_procstate *) &(skb->cb[0]);
980 static inline struct sk_buff *skb_from_pstate(struct skb_procstate *ps)
982 return (struct sk_buff *) (((char *)ps) - offsetof(struct sk_buff,cb));
986 static inline __u32 mss(struct neighbor *nb)
988 return nb->dev->mtu - LL_RESERVED_SPACE(nb->dev) - 9;
992 static inline void put_u64(char *dst, __u64 value, int convbo)
994 char *p_value = (char *) &value;
996 if (convbo)
997 value = cpu_to_be64(value);
999 dst[0] = p_value[0];
1000 dst[1] = p_value[1];
1001 dst[2] = p_value[2];
1002 dst[3] = p_value[3];
1003 dst[4] = p_value[4];
1004 dst[5] = p_value[5];
1005 dst[6] = p_value[6];
1006 dst[7] = p_value[7];
1009 static inline void put_u32(char *dst, __u32 value, int convbo)
1011 char *p_value = (char *) &value;
1013 if (convbo)
1014 value = cpu_to_be32(value);
1016 dst[0] = p_value[0];
1017 dst[1] = p_value[1];
1018 dst[2] = p_value[2];
1019 dst[3] = p_value[3];
1022 static inline void put_u16(char *dst, __u16 value, int convbo)
1024 char *p_value = (char *) &value;
1026 if (convbo)
1027 value = cpu_to_be16(value);
1029 dst[0] = p_value[0];
1030 dst[1] = p_value[1];
1033 static inline char *cor_pull_skb(struct sk_buff *skb, unsigned int len)
1035 char *ptr = skb_pull(skb, len);
1037 if(unlikely(ptr == 0))
1038 return 0;
1040 return ptr - len;
1044 static inline __u64 mul_saturated(__u64 a, __u64 b)
1046 __u64 res = a*b;
1047 if (res / a != b)
1048 return -1;
1049 return res;
1052 static inline int numdigits(__u64 value)
1054 int digits = 0;
1055 for (;value != 0;value = (value >> 1)) {
1056 digits++;
1058 return digits;
1061 /* approximate (a*b) / c without overflowing a*b */
1062 static inline __u64 multiply_div(__u64 a, __u64 b, __u64 c)
1064 int alen = numdigits(a);
1065 int blen = numdigits(b);
1066 int clen = numdigits(c);
1068 BUG_ON(alen < 0 || alen > 64);
1069 BUG_ON(blen < 0 || blen > 64);
1070 BUG_ON(clen < 0 || clen > 64);
1072 BUG_ON((a == 0 && alen != 0) || (a != 0 && alen == 0));
1073 BUG_ON((b == 0 && blen != 0) || (b != 0 && blen == 0));
1074 BUG_ON((c == 0 && clen != 0) || (c != 0 && clen == 0));
1076 BUG_ON(a >= b && alen < blen);
1077 BUG_ON(a >= c && alen < clen);
1078 BUG_ON(b >= a && blen < alen);
1079 BUG_ON(b >= c && blen < clen);
1080 BUG_ON(c >= a && clen < alen);
1081 BUG_ON(c >= b && clen < blen);
1083 if (alen == 0 || blen == 0)
1084 return 0;
1086 BUG_ON(c == 0);
1088 if (alen + blen <= 64)
1089 return (a*b)/c;
1091 if (a >= b && alen > clen + 16)
1092 return mul_saturated(a/c, b);
1093 else if (a < b && blen > clen + 16)
1094 return mul_saturated(b/c, a);
1096 while (alen + blen > 64) {
1097 if (alen > blen || (alen == blen && a > b)) {
1098 alen--;
1099 a = (a >> 1);
1100 } else {
1101 blen--;
1102 b = (b >> 1);
1104 clen--;
1105 c = (c >> 1);
1108 return (a*b)/c;