qos fixes, reset bufferusage on conn reset, conn refcnt fix
[cor_2_6_31.git] / net / cor / cor.h
blobd21bf34131d9afbb7a087b2bce1b44c246a676f7
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[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[4]
188 * addrtypelen[2] addrlen[2] addrtype[addrtypelen] addr[addrlen] */
189 #define CD_CONNECT_NB 1
191 /* connection to local open part: CD_CONNECT_PORT[2] length[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[4] response_rows[4]
199 * for every row:
200 * numaddr[2] (addrtypelen[2] addrlen[2] addrtype[addrtypelen] addr[addrlen]
201 * )[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[4] limit[4] offset[4] */
210 #define CD_LIST_NEIGH 3
213 * CD_SET_(FORWARD|BACKWARD)_TIMEOUT[2] length[4] timeout_ms[4]
215 * If there is no successful communication with the previous or neighbor for
216 * this period, the connection will be reset. This value must be between
217 * NB_STALL_TIME and NB_KILL_TIME. Otherwise it will silently behave as if it
218 * was set to exactly one of these limits.
220 #define CD_SET_FORWARD_TIMEOUT 4
221 #define CD_SET_BACKWARD_TIMEOUT 5
224 * Connection data response
225 * Format is the same as with connection data
229 * {CDR_EXECOK[2] || CDR_EXECFAILED[2]}
230 * reasoncode[2] reasontextlength[2] reasontext[reasontextlength]
231 * reasontextlength may be 0
233 #define CDR_EXECOK 32768
234 #define CDR_EXECOK_OK 33024
237 #define CDR_EXECFAILED 32769
238 #define CDR_EXECFAILED_UNKNOWN_COMMAND 33280
239 #define CDR_EXECFAILED_PERMISSION_DENIED 33281
240 #define CDR_EXECFAILED_TEMPORARILY_OUT_OF_RESSOURCES 33282
241 #define CDR_EXECFAILED_CMD_TOO_SHORT 33283
242 #define CDR_EXECFAILED_CMD_TOO_LONG 33284
243 #define CDR_EXECFAILED_TARGETADDRTYPE_UNKNOWN 33285
244 #define CDR_EXECFAILED_TARGETADDR_DOESNTEXIST 33286
245 #define CDR_EXECFAILED_TARGETADDR_PORTCLOSED 33287
246 #define CDR_EXECFAILED_LISTENERQUEUE_FULL 33288
247 #define CDR_EXECFAILED_ILLEGAL_COMMAND 33289
250 * must be sent after CDR_EXEC{OK|FAILED}
251 * CDR_EXEOK_BINDATA[2] bindatalen[4] bindata[bindatalen] */
252 #define CDR_BINDATA 32770
255 /* result codes for rcv.c/proc_packet */
256 #define RC_DROP 0
257 #define RC_FINISHED 1
259 #define RC_RCV1_ANNOUNCE 2
260 #define RC_RCV1_KERNEL 3
261 #define RC_RCV1_CONN 4
263 struct htab_entry{
264 /* start of next element, *not* next htab_entry */
265 void *next;
268 struct htable{
269 struct htab_entry **htable;
270 __u32 htable_size;
271 __u32 cell_size;
272 __u32 num_elements;
274 int (*matches)(void *htentry, void *searcheditem);
275 __u32 key_offset;
276 __u32 entry_offset;
277 __u32 kref_offset;
280 struct resume_block{
281 struct list_head lh;
282 int in_queue;
285 struct announce_data{
286 struct kref ref;
288 struct list_head lh;
289 struct net_device *dev;
290 struct delayed_work announce_work;
291 struct announce *ann;
292 struct resume_block rb;
294 __u32 curr_announce_msg_offset;
295 __u64 scheduled_announce_timer;
298 struct ping_cookie{
299 unsigned long time;
300 __u32 cookie;
301 __u8 pongs; /* count of pongs for pings sent after this one */
304 #define NEIGHBOR_STATE_INITIAL 0
305 #define NEIGHBOR_STATE_ACTIVE 1
306 #define NEIGHBOR_STATE_STALLED 2
307 #define NEIGHBOR_STATE_KILLED 3
309 struct neighbor{
310 struct list_head nb_list;
312 struct kref ref;
314 struct net_device *dev;
315 char mac[MAX_ADDR_LEN];
317 char *addr;
318 __u16 addrlen;
320 struct delayed_work cmsg_timer;
321 struct mutex cmsg_lock;
322 struct list_head control_msgs_out;
324 * urgent messages; These are sent even if the neighbor state is not
325 * active. If the queue gets full, the oldest ones are dropped. It thus
326 * may only contain messages which are allowed to be dropped.
328 struct list_head ucontrol_msgs_out;
329 __u64 timeout;
330 __u32 cmlength;
331 __u32 ucmlength;
333 atomic_t cmcnt; /* size of queue + retransmits */
334 atomic_t ucmcnt; /* size of queue only */
336 __u8 ping_all_conns;
337 __u8 send_credits;
338 __u8 max_cmsg_delay_sent;
340 /* see snd.c/qos_queue */
341 /* protected by cmsg_lock */
342 __u8 kp_allmsgs;
344 /* procected by queues_lock */
345 struct resume_block rb_kp;
346 struct resume_block rb_cr;
348 struct mutex pingcookie_lock;
349 unsigned long last_ping_time;
350 __u32 ping_intransit;
351 struct ping_cookie cookies[PING_COOKIES_PER_NEIGH];
352 __u32 lastcookie;
353 atomic_t latency; /* microsecs */
354 atomic_t max_remote_cmsg_delay; /* microsecs */
356 spinlock_t state_lock;
357 union {
358 __u64 last_state_change;/* initial state */
360 * last_roundtrip:
361 * time of the last sent packet which has been acked or
362 * otherwise responded to (e.g. pong)
364 unsigned long last_roundtrip;/* active/stalled state */
365 }state_time;
366 __u8 state;
367 __u16 ping_success;
369 struct delayed_work stalltimeout_timer;
370 __u8 str_timer_pending;
373 atomic_t kpacket_seqno;
374 atomic_t ooo_packets;
376 spinlock_t credits_lock;
377 long jiffies_credit_update;
379 /* all cretid rates are in credits/ms */
380 __u64 credits; /* how much we can spend */
381 __u32 credits_fract;
382 __u64 credits_diff; /* diff between the neighbor's and our calc */
383 __u32 credits_diff_fract;
384 __s32 creditrate_initial;
385 __u32 creditrate_earning;
386 __u32 creditrate_spending;
387 __u32 creditrate_spending_expected;
389 __s32 creditrate_spending_diff;
391 __u64 debits; /* how much the other side can spend */
392 __u32 debits_fract;
393 __s32 debitrate_initial;
394 __s32 debitrate_initial_adj;
395 __u32 debitrate_earning;
396 __u32 debitrate_spending;
400 * connecions which receive data from/send data to this node
401 * used when terminating all connections of a neighbor
403 struct mutex conn_list_lock;
404 struct list_head rcv_conn_list;
405 struct list_head snd_conn_list;
406 __u32 num_send_conns;
409 * used for ping_all conns, if not zero this is the next conn we need to
410 * ping, protected by conn_list_lock
412 struct conn *next_ping_conn;
413 __u32 ping_conns_remaining;
414 __u32 ping_conns_retrans_remaining;
415 __u32 pong_conns_expected;
416 unsigned long ping_conn_completed; /* jiffies */
419 * the timer has to be inited when adding the neighbor
420 * init_timer(struct timer_list * timer);
421 * add_timer(struct timer_list * timer);
423 spinlock_t retrans_lock;
424 struct delayed_work retrans_timer_conn;
425 struct delayed_work retrans_timer;
426 __u8 retrans_timer_conn_running;
427 __u8 retrans_timer_running;
429 struct list_head retrans_list;
430 struct list_head retrans_list_conn;
432 struct conn *firstboundconn;
435 struct cor_sched_data{
436 spinlock_t lock;
437 struct list_head conn_list;
438 struct sk_buff_head requeue_queue;
441 #define TYPE_BUF 0
442 #define TYPE_SKB 1
444 struct data_buf_item{
445 struct list_head buf_list;
447 union {
448 struct {
449 char *buf;
450 __u32 datalen;
452 }buf;
454 struct sk_buff *skb;
455 }data;
457 __u8 type;
460 struct data_buf{
461 struct list_head items;
462 struct data_buf_item *lastread;
463 __u32 first_offset;
465 __u32 totalsize;
466 __u32 read_remaining;
468 __u16 last_read_offset;
470 __u16 last_buflen;
473 struct connlistener;
475 struct bindnode{
476 struct list_head lh;
477 struct connlistener *owner;
478 __be64 port;
481 #define SOCKSTATE_LISTENER 1
482 #define SOCKSTATE_CONN 2
484 struct sock_hdr {
485 /* The first member of connlistener/conn (see sock.c) */
486 __u8 sockstate;
489 struct connlistener {
490 /* The first member has to be the same as in conn (see sock.c) */
491 __u8 sockstate;
492 struct bindnode *bn;
493 struct mutex lock;
494 int queue_maxlen;
495 int queue_len;
496 struct list_head conn_queue;
497 wait_queue_head_t wait;
501 struct speedtracker{
502 __u64 speed;/* bytes*65536/jiffie */
503 unsigned long jiffies_last_update;
504 __u32 bytes_curr;
508 * There are 2 conn objects per bi-directional connection. They refer to each
509 * other with in the reversedir field. To distinguish them, the variables on
510 * the stack are usually called rconn and sconn. rconn refers to the conn object
511 * which has received a command. sconn is the other conn object. This means that
512 * in send functions rconn means the connection we want to send the command to.
515 struct conn{
516 /* The first member has to be the same as in connlistener (see sock.c)*/
517 __u8 sockstate;
519 #define SOURCE_NONE 0
520 #define SOURCE_IN 1
521 #define SOURCE_SOCK 2
523 #define TARGET_UNCONNECTED 0
524 #define TARGET_OUT 1
525 #define TARGET_SOCK 2
527 __u8 sourcetype:4,
528 targettype:4;
531 * isreset values:
532 * 0... connection active
533 * 1... connection is about to be reset, target does not need to be
534 * notified
535 * 2... connection is reset
536 * 3... connection is reset + no pointers to "struct conn *reversedir"
537 * remaining except from this conn
539 atomic_t isreset;
541 struct list_head queue_list;
543 struct kref ref;
546 * locking order:
547 * If one side is SOCK or NONE/UNCONNECTED and both directions
548 * need to be locked, the direction with TARGET_UNCONNECTED or
549 * TARGET_SOCK has to be locked first, the direction with
550 * SOURCE_NONE or SOURCE_SOCK afterwards. If one side is TARGET_SOCK
551 * and the other is TARGET_UNCONNECTED, TARGET_SOCK needs to be locked
552 * first. This is needed for changing source/targettype, credit flow
553 * and TARGET_UNCONNECTED generating responses.
554 * If data is forwarded, (both sides are IN/OUT), only one direction
555 * may be locked.
557 struct mutex rcv_lock;
559 long jiffies_credit_update;
560 /* state */
561 __s64 credits;
562 __u32 credits_fract;
563 /* credit rates, locked by credit_lock (in credit.c) */
564 __u32 sender_crate;
565 __u32 recp_crate;
567 union{
568 struct{
569 struct neighbor *nb;
570 /* list of all connections from this neighbor */
571 struct list_head nb_list;
573 struct sk_buff_head reorder_queue;
575 struct htab_entry htab_entry;
576 __u32 conn_id;
577 __u32 next_seqno;
578 __u32 ooo_packets;
580 atomic_t pong_awaiting;
582 /* credit rate */
583 __u32 crate_in_raw;
585 __u32 window_seqnolimit_max;
586 __u32 window_seqnolimit_last;
588 struct list_head buffer_list;
590 __u32 buffer_init;
591 __u32 buffer_speed;
592 __u32 buffer_ata;
594 __u32 usage_init;
595 __u32 usage_speed;
596 __u32 usage_ata;
597 __u32 usage_reserve;
599 struct speedtracker st;
601 unsigned long jiffies_last_window_set;
602 }in;
604 struct{
605 struct list_head cl_list;
606 wait_queue_head_t wait;
607 struct socket *sock;
608 int flags;
610 __u32 crate;
611 }sock;
612 }source;
614 union{
615 struct{
616 __u32 paramlen;
617 __u32 cmdread;
618 __u16 cmd;
619 __u8 *cmdparams;
621 __u32 stall_timeout_ms;
622 }unconnected;
624 struct{
625 /* has to be first (because it is first in target
626 * kernel too)
628 struct neighbor *nb;
629 /* list of all connections to this neighbor */
630 struct list_head nb_list;
631 /* protected by nb->retrans_lock, sorted by seqno */
632 struct list_head retrans_list;
634 /* reverse conn_id lookup */
635 struct htab_entry htab_entry;
637 __u32 conn_id;
638 __u32 seqno_nextsend;
639 __u32 seqno_acked;
640 __u32 seqno_windowlimit;
641 __u32 kp_windowsetseqno;
643 struct resume_block rb;
645 __u32 stall_timeout_ms;
647 /* credit rate */
648 __u32 crate_out_raw;
649 }out;
651 struct{
652 wait_queue_head_t wait;
654 __u8 credituser;
655 }sock;
656 }target;
658 struct data_buf buf;
660 struct conn *reversedir;
663 /* inside skb->cb */
664 struct skb_procstate{
665 union{
666 struct{
667 struct work_struct work;
668 }rcv;
670 struct{
671 __u32 offset;
672 }announce;
674 struct{
675 __u32 seqno;
676 }rcv2;
677 }funcstate;
681 /* common.c */
682 extern atomic_t num_conns;
684 extern __u8 enc_window(__u32 window_bytes);
686 extern __u32 dec_window(__u8 window);
688 extern char *htable_get(struct htable *ht, __u32 key, void *searcheditem);
690 extern int htable_delete(struct htable *ht, __u32 key, void *searcheditem,
691 void (*free) (struct kref *ref));
693 extern void htable_insert(struct htable *ht, char *newelement, __u32 key);
695 extern void htable_init(struct htable *ht, int (*matches)(void *htentry,
696 void *searcheditem), __u32 entry_offset,
697 __u32 kref_offset);
699 extern struct conn *get_conn_reverse(struct neighbor *nb, __u32 conn_id);
701 extern void insert_reverse_connid(struct conn *rconn);
703 extern struct conn *get_conn(__u32 conn_id);
705 extern void free_conn(struct kref *ref);
707 extern int conn_init_out(struct conn *rconn, struct neighbor *nb);
709 extern void conn_init_sock_source(struct conn *conn);
711 extern void conn_init_sock_target(struct conn *conn);
713 extern void close_port(struct connlistener *listener);
715 extern struct connlistener *open_port(__be64 port);
717 extern int connect_port(struct conn *rconn, __be64 port);
719 extern int connect_neigh(struct conn *rconn,
720 __u16 addrtypelen, __u8 *addrtype,
721 __u16 addrlen, __u8 *addr);
723 extern struct conn* alloc_conn(gfp_t allocflags);
725 extern void reset_ping(struct conn *rconn);
727 extern void reset_conn(struct conn *conn);
729 /* credits.c */
730 extern int refresh_credits_state(struct neighbor *nb);
732 extern void check_credit_state(struct neighbor *nb);
734 extern int debit_adj_needed(struct neighbor *nb);
736 extern void refresh_conn_credits(struct conn *conn);
738 extern void set_credits(struct neighbor *nb, __u64 credits,
739 __s32 creditrate_initial, __u32 creditrate_earning,
740 __u32 creditrate_spending);
742 extern void set_debitrate_initial(struct neighbor *nb, __u32 debitrate);
744 extern void set_conn_in_crate(struct conn *rconn, __u32 crate_in);
746 extern int __init cor_credits_init(void);
748 /* neighbor.c */
749 extern void neighbor_free(struct kref *ref);
751 extern struct neighbor *get_neigh_by_mac(struct sk_buff *skb);
753 extern struct neighbor *find_neigh(__u16 addrtypelen, __u8 *addrtype,
754 __u16 addrlen, __u8 *addr);
756 extern __u32 generate_neigh_list(char *buf, __u32 buflen, __u32 limit,
757 __u32 offset);
759 extern int get_neigh_state(struct neighbor *nb);
761 extern void ping_resp(struct neighbor *nb, __u32 cookie, __u32 respdelay);
763 extern __u32 add_ping_req(struct neighbor *nb);
765 extern void unadd_ping_req(struct neighbor *nb, __u32 cookie);
767 extern int time_to_send_ping(struct neighbor *nb);
769 extern int force_ping(struct neighbor *nb);
771 extern void rcv_announce(struct sk_buff *skb);
773 extern int send_announce_qos(struct announce_data *ann);
775 extern void announce_data_free(struct kref *ref);
777 extern int __init cor_neighbor_init(void);
779 /* rcv.c */
780 extern __u32 get_window(struct conn *rconn);
782 extern void reset_bufferusage(struct conn *conn);
784 extern void refresh_speedstat(struct conn *rconn, __u32 written);
786 extern void drain_ooo_queue(struct conn *rconn);
788 extern void conn_rcv_buildskb(char *data, __u32 datalen, __u32 conn_id,
789 __u32 seqno);
791 extern int __init cor_rcv_init(void);
793 /* kpacket_parse.c */
794 extern void kernel_packet(struct neighbor *nb, struct sk_buff *skb, __u32 seqno);
796 /* kpacket_gen.c */
797 extern void schedule_controlmsg_timerfunc(struct neighbor *nb);
799 struct control_msg_out;
801 #define ACM_PRIORITY_LOW 1
802 #define ACM_PRIORITY_MED 2
803 #define ACM_PRIORITY_HIGH 3
805 extern struct control_msg_out *alloc_control_msg(struct neighbor *nb,
806 int priority);
808 extern void free_control_msg(struct control_msg_out *cm);
810 extern void retransmit_timerfunc(struct work_struct *work);
812 extern void kern_ack_rcvd(struct neighbor *nb, __u32 seqno);
814 extern int resume_send_messages(struct neighbor *nb);
816 extern void send_pong(struct neighbor *nb,
817 __u32 cookie);
819 extern void send_reset_conn(struct control_msg_out *cm, __u32 conn_id);
821 extern void send_ack(struct neighbor *nb,
822 __u32 seqno);
824 extern void send_ack_conn(struct control_msg_out *cm, struct conn *rconn,
825 __u32 conn_id, __u32 seqno);
827 extern void send_ack_conn_ooo(struct control_msg_out *cm, struct conn *rconn,
828 __u32 conn_id, __u32 seqno, __u32 seqno_ooo, __u32 length);
830 extern void send_connect_success(struct control_msg_out *cm, __u32 rcvd_conn_id,
831 __u32 gen_conn_id, __u32 init_seqno, struct conn *rconn);
833 extern void send_connect_nb(struct control_msg_out *cm, __u32 conn_id,
834 __u32 init_seqno, struct conn *sconn);
836 extern void send_conndata(struct control_msg_out *cm, __u32 conn_id,
837 __u32 seqno, char *data_orig, char *data, __u32 datalen);
839 extern void send_ping_conn(struct control_msg_out *cm, __u32 conn_id);
841 extern void send_connid_unknown(struct control_msg_out *cm, __u32 conn_id);
843 extern void send_ping_all_conns(struct neighbor *nb);
845 extern void send_credits(struct neighbor *nb);
847 extern void cor_kgen_init(void);
849 /* cpacket_parse.c */
850 extern void parse(struct conn *rconn);
852 /* snd.c */
853 extern int destroy_queue(struct net_device *dev);
855 extern int create_queue(struct net_device *dev);
857 #define QOS_CALLER_KPACKET 0
858 #define QOS_CALLER_CONN_RETRANS 1
859 #define QOS_CALLER_ANNOUNCE 2
860 #define QOS_CALLER_CONN 3
862 extern void qos_enqueue(struct net_device *dev, struct resume_block *rb,
863 int caller);
865 extern void qos_enqueue_kpacket(struct neighbor *nb);
867 extern void qos_remove_conn(struct conn *rconn);
869 extern void qos_enqueue_conn(struct conn *rconn, int oom);
871 extern struct sk_buff *create_packet(struct neighbor *nb, int size,
872 gfp_t alloc_flags, __u32 conn_id, __u32 seqno);
874 extern void cancel_retrans(struct conn *rconn);
876 extern void retransmit_conn_timerfunc(struct work_struct *work);
878 extern void conn_ack_rcvd(__u32 kpacket_seqno, struct conn *rconn, __u32 seqno,
879 __u8 window, __u32 seqno_ooo, __u32 length);
881 #define RC_FLUSH_CONN_OUT_OK 0
882 #define RC_FLUSH_CONN_OUT_CONG 1
883 #define RC_FLUSH_CONN_OUT_CREDITS 2
884 #define RC_FLUSH_CONN_OUT_OOM 3
885 extern int flush_out(struct conn *rconn);
887 extern int __init cor_snd_init(void);
889 /* forward.c */
890 extern void databuf_pull(struct data_buf *data, char *dst, int len);
892 extern size_t databuf_pulluser(struct conn *sconn, struct msghdr *msg);
894 extern void databuf_unpull(struct data_buf *data, __u32 bytes);
896 extern void databuf_pullold(struct data_buf *data, __u32 startpos, char *dst,
897 int len);
899 extern void databuf_ack(struct conn *rconn, __u32 pos);
901 extern void databuf_ackread(struct conn *rconn);
903 extern int databuf_maypush(struct data_buf *buf);
905 extern void flush_buf(struct conn *rconn);
907 extern void reset_seqno(struct data_buf *buf, __u32 initseqno);
909 extern void databuf_free(struct data_buf *data);
911 extern void databuf_init(struct data_buf *data);
913 extern int receive_userbuf(struct conn *rconn, struct msghdr *msg);
915 extern void receive_buf(struct conn *rconn, char *buf, int len);
917 extern int receive_skb(struct conn *rconn, struct sk_buff *skb);
919 extern void wake_sender(struct conn *rconn);
921 extern void forward_init(void);
924 static inline struct skb_procstate *skb_pstate(struct sk_buff *skb)
926 return (struct skb_procstate *) &(skb->cb[0]);
929 static inline struct sk_buff *skb_from_pstate(struct skb_procstate *ps)
931 return (struct sk_buff *) (((char *)ps) - offsetof(struct sk_buff,cb));
935 static inline __u32 mss(struct neighbor *nb)
937 return nb->dev->mtu - LL_RESERVED_SPACE(nb->dev) - 9;
941 static inline void put_u64(char *dst, __u64 value, int convbo)
943 char *p_value = (char *) &value;
945 if (convbo)
946 value = cpu_to_be64(value);
948 dst[0] = p_value[0];
949 dst[1] = p_value[1];
950 dst[2] = p_value[2];
951 dst[3] = p_value[3];
952 dst[4] = p_value[4];
953 dst[5] = p_value[5];
954 dst[6] = p_value[6];
955 dst[7] = p_value[7];
958 static inline void put_u32(char *dst, __u32 value, int convbo)
960 char *p_value = (char *) &value;
962 if (convbo)
963 value = cpu_to_be32(value);
965 dst[0] = p_value[0];
966 dst[1] = p_value[1];
967 dst[2] = p_value[2];
968 dst[3] = p_value[3];
971 static inline void put_u16(char *dst, __u16 value, int convbo)
973 char *p_value = (char *) &value;
975 if (convbo)
976 value = cpu_to_be16(value);
978 dst[0] = p_value[0];
979 dst[1] = p_value[1];
982 static inline char *cor_pull_skb(struct sk_buff *skb, unsigned int len)
984 char *ptr = skb_pull(skb, len);
986 if(unlikely(ptr == 0))
987 return 0;
989 return ptr - len;
993 static inline __u64 mul_saturated(__u64 a, __u64 b)
995 __u64 res = a*b;
996 if (res / a != b)
997 return -1;
998 return res;
1001 static inline int numdigits(__u64 value)
1003 int digits = 0;
1004 for (;value != 0;value = (value >> 1)) {
1005 digits++;
1007 return digits;
1010 /* approximate (a*b) / c without overflowing a*b */
1011 static inline __u64 multiply_div(__u64 a, __u64 b, __u64 c)
1013 int alen = numdigits(a);
1014 int blen = numdigits(b);
1015 int clen = numdigits(c);
1017 BUG_ON(alen < 0 || alen > 64);
1018 BUG_ON(blen < 0 || blen > 64);
1019 BUG_ON(clen < 0 || clen > 64);
1021 BUG_ON((a == 0 && alen != 0) || (a != 0 && alen == 0));
1022 BUG_ON((b == 0 && blen != 0) || (b != 0 && blen == 0));
1023 BUG_ON((c == 0 && clen != 0) || (c != 0 && clen == 0));
1025 BUG_ON(a >= b && alen < blen);
1026 BUG_ON(a >= c && alen < clen);
1027 BUG_ON(b >= a && blen < alen);
1028 BUG_ON(b >= c && blen < clen);
1029 BUG_ON(c >= a && clen < alen);
1030 BUG_ON(c >= b && clen < blen);
1032 if (alen == 0 || blen == 0)
1033 return 0;
1035 BUG_ON(c == 0);
1037 if (alen + blen <= 64)
1038 return (a*b)/c;
1040 if (a >= b && alen > clen + 16)
1041 return mul_saturated(a/c, b);
1042 else if (a < b && blen > clen + 16)
1043 return mul_saturated(b/c, a);
1045 while (alen + blen > 64) {
1046 if (alen > blen || (alen == blen && a > b)) {
1047 alen--;
1048 a = (a >> 1);
1049 } else {
1050 blen--;
1051 b = (b >> 1);
1053 clen--;
1054 c = (c >> 1);
1057 return (a*b)/c;