connreset_cpacket_buffer, credits, enlarge window upon resume, unconnected->buffer_wa...
[cor_2_6_31.git] / net / cor / cor.h
blob1b6eebe440dded1660fb08225e0af6ce18b59fab
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
214 * CD_SET_(FORWARD|BACKWARD)_TIMEOUT[2] length[1-4] timeout_ms[4]
216 * If there is no successful communication with the previous or neighbor for
217 * this period, the connection will be reset. This value must be between
218 * NB_STALL_TIME and NB_KILL_TIME. Otherwise it will silently behave as if it
219 * was set to exactly one of these limits.
221 #define CD_SET_FORWARD_TIMEOUT 4
222 #define CD_SET_BACKWARD_TIMEOUT 5
226 * CD_SET_TOS[2] length[1-4] forward_tos[1] backward_tos[1]
227 * Only 2 bits of the tos flags are used, the highers 6 bits are ignored.
229 #define CD_SET_TOS 6
231 #define TOS_NORMAL 0
232 #define TOS_LATENCY 1
233 #define TOS_THROUGHPUT 2
234 #define TOS_PRIVACY 3
239 * Connection data response
240 * Format is the same as with connection data
244 * CDR_EXECOK[1]
246 #define CDR_EXECOK 1
249 * CDR_EXECFAILED[1] reasoncode[2]
250 * reasontextlength[1-4] reasontext[reasontextlength]
251 * reasontextlength may be 0
253 #define CDR_EXECFAILED 2
254 #define CDR_EXECFAILED_UNKNOWN_COMMAND 1
255 #define CDR_EXECFAILED_PERMISSION_DENIED 2
256 #define CDR_EXECFAILED_TEMPORARILY_OUT_OF_RESSOURCES 3
257 #define CDR_EXECFAILED_CMD_TOO_SHORT 4
258 #define CDR_EXECFAILED_CMD_TOO_LONG 5
259 #define CDR_EXECFAILED_TARGETADDRTYPE_UNKNOWN 6
260 #define CDR_EXECFAILED_TARGETADDR_DOESNTEXIST 7
261 #define CDR_EXECFAILED_TARGETADDR_PORTCLOSED 8
262 #define CDR_EXECFAILED_LISTENERQUEUE_FULL 9
263 #define CDR_EXECFAILED_ILLEGAL_COMMAND 10
266 * must be sent after CDR_EXEC{OK|FAILED}
267 * CDR_EXEOK_BINDATA[1] bindatalen[1-4] bindata[bindatalen] */
268 #define CDR_BINDATA 3
271 /* result codes for rcv.c/proc_packet */
272 #define RC_DROP 0
273 #define RC_FINISHED 1
275 #define RC_RCV1_ANNOUNCE 2
276 #define RC_RCV1_KERNEL 3
277 #define RC_RCV1_CONN 4
279 struct htab_entry{
280 /* start of next element, *not* next htab_entry */
281 void *next;
284 struct htable{
285 struct htab_entry **htable;
286 __u32 htable_size;
287 __u32 cell_size;
288 __u32 num_elements;
290 int (*matches)(void *htentry, void *searcheditem);
291 __u32 key_offset;
292 __u32 entry_offset;
293 __u32 kref_offset;
296 struct resume_block{
297 struct list_head lh;
298 int in_queue;
301 struct announce_data{
302 struct kref ref;
304 struct list_head lh;
305 struct net_device *dev;
306 struct delayed_work announce_work;
307 struct announce *ann;
308 struct resume_block rb;
310 __u32 curr_announce_msg_offset;
311 __u64 scheduled_announce_timer;
314 struct ping_cookie{
315 unsigned long time;
316 __u32 cookie;
317 __u8 pongs; /* count of pongs for pings sent after this one */
320 #define NEIGHBOR_STATE_INITIAL 0
321 #define NEIGHBOR_STATE_ACTIVE 1
322 #define NEIGHBOR_STATE_STALLED 2
323 #define NEIGHBOR_STATE_KILLED 3
325 struct neighbor{
326 struct list_head nb_list;
328 struct kref ref;
330 struct net_device *dev;
331 char mac[MAX_ADDR_LEN];
333 char *addr;
334 __u16 addrlen;
336 struct delayed_work cmsg_timer;
337 struct mutex cmsg_lock;
338 struct list_head control_msgs_out;
340 * urgent messages; These are sent even if the neighbor state is not
341 * active. If the queue gets full, the oldest ones are dropped. It thus
342 * may only contain messages which are allowed to be dropped.
344 struct list_head ucontrol_msgs_out;
345 unsigned long timeout;
346 __u32 cmlength;
347 __u32 ucmlength;
349 atomic_t cmcnt; /* size of queue + retransmits */
350 atomic_t ucmcnt; /* size of queue only */
352 __u8 ping_all_conns;
353 __u8 send_credits;
354 __u8 max_cmsg_delay_sent;
356 /* see snd.c/qos_queue */
357 /* protected by cmsg_lock */
358 __u8 kp_allmsgs;
360 /* procected by queues_lock */
361 struct resume_block rb_kp;
362 struct resume_block rb_cr;
364 struct mutex pingcookie_lock;
365 unsigned long last_ping_time;
366 __u32 ping_intransit;
367 struct ping_cookie cookies[PING_COOKIES_PER_NEIGH];
368 __u32 lastcookie;
369 atomic_t latency; /* microsecs */
370 atomic_t max_remote_cmsg_delay; /* microsecs */
372 spinlock_t state_lock;
373 union {
374 __u64 last_state_change;/* initial state */
376 * last_roundtrip:
377 * time of the last sent packet which has been acked or
378 * otherwise responded to (e.g. pong)
380 unsigned long last_roundtrip;/* active/stalled state */
381 }state_time;
382 __u8 state;
383 __u16 ping_success;
385 struct delayed_work stalltimeout_timer;
386 __u8 str_timer_pending;
389 atomic_t kpacket_seqno;
390 atomic_t ooo_packets;
392 spinlock_t credits_lock;
393 long jiffies_credit_update;
395 /* all cretid rates are in credits/ms */
396 __u64 credits; /* how much we can spend */
397 __u32 credits_fract;
398 __u64 credits_diff; /* diff between the neighbor's and our calc */
399 __u32 credits_diff_fract;
400 __s32 creditrate_initial;
401 __u32 creditrate_earning;
402 __u32 creditrate_spending;
403 __u32 creditrate_spending_expected;
405 __s32 creditrate_spending_diff;
407 __u64 debits; /* how much the other side can spend */
408 __u32 debits_fract;
409 __s32 debitrate_initial;
410 __s32 debitrate_initial_adj;
411 __u32 debitrate_earning;
412 __u32 debitrate_spending;
415 * connecions which receive data from/send data to this node
416 * used when terminating all connections of a neighbor
418 struct mutex conn_list_lock;
419 struct list_head rcv_conn_list;
420 struct list_head snd_conn_list;
421 __u32 num_send_conns;
424 * used for ping_all conns, if not zero this is the next conn we need to
425 * ping, protected by conn_list_lock
427 struct conn *next_ping_conn;
428 __u32 ping_conns_remaining;
429 __u32 ping_conns_retrans_remaining;
430 __u32 pong_conns_expected;
431 unsigned long ping_conn_completed; /* jiffies */
434 * the timer has to be inited when adding the neighbor
435 * init_timer(struct timer_list * timer);
436 * add_timer(struct timer_list * timer);
438 spinlock_t retrans_lock;
439 struct delayed_work retrans_timer_conn;
440 struct delayed_work retrans_timer;
441 __u8 retrans_timer_conn_running;
442 __u8 retrans_timer_running;
444 struct list_head retrans_list;
445 struct list_head retrans_list_conn;
447 struct conn *firstboundconn;
450 struct cor_sched_data{
451 spinlock_t lock;
452 struct list_head conn_list;
453 struct sk_buff_head requeue_queue;
456 #define TYPE_BUF 0
457 #define TYPE_SKB 1
459 struct data_buf_item{
460 struct list_head buf_list;
462 union {
463 struct {
464 char *buf;
465 __u16 datalen;
466 __u16 buflen;
468 }buf;
470 struct sk_buff *skb;
471 }data;
473 __u8 type;
476 struct connlistener;
478 struct bindnode{
479 struct list_head lh;
480 struct connlistener *owner;
481 __be64 port;
484 #define SOCKSTATE_LISTENER 1
485 #define SOCKSTATE_CONN 2
487 struct sock_hdr {
488 /* The first member of connlistener/conn (see sock.c) */
489 __u8 sockstate;
492 struct connlistener {
493 /* The first member has to be the same as in conn (see sock.c) */
494 __u8 sockstate;
495 struct bindnode *bn;
496 struct mutex lock;
497 int queue_maxlen;
498 int queue_len;
499 struct list_head conn_queue;
500 wait_queue_head_t wait;
504 struct speedtracker{
505 __u64 speed;/* bytes*65536/jiffie */
506 unsigned long jiffies_last_update;
507 __u32 bytes_curr;
511 * There are 2 conn objects per bi-directional connection. They refer to each
512 * other with in the reversedir field. To distinguish them, the variables on
513 * the stack are usually called rconn and sconn. rconn refers to the conn object
514 * which has received a command. sconn is the other conn object.
516 struct conn{
517 /* The first member has to be the same as in connlistener (see sock.c)*/
518 __u8 sockstate;
520 #define SOURCE_NONE 0
521 #define SOURCE_IN 1
522 #define SOURCE_SOCK 2
524 #define TARGET_UNCONNECTED 0
525 #define TARGET_OUT 1
526 #define TARGET_SOCK 2
528 __u8 sourcetype:4,
529 targettype:4;
531 __u8 tos;
533 __u8 last_bufferstate:1,
534 in_credit_list:1;
537 * isreset values:
538 * 0... connection active
539 * 1... connection is about to be reset, target does not need to be
540 * notified
541 * 2... connection is reset
542 * 3... connection is reset + no pointers to "struct conn *reversedir"
543 * remaining except from this conn
545 atomic_t isreset;
547 struct list_head queue_list;
549 struct kref ref;
552 * locking order:
553 * If one side is SOCK or NONE/UNCONNECTED and both directions
554 * need to be locked, the direction with TARGET_UNCONNECTED or
555 * TARGET_SOCK has to be locked first, the direction with
556 * SOURCE_NONE or SOURCE_SOCK afterwards. If one side is TARGET_SOCK
557 * and the other is TARGET_UNCONNECTED, TARGET_SOCK needs to be locked
558 * first. This is needed for changing source/targettype, credit flow
559 * and TARGET_UNCONNECTED generating responses.
560 * If data is forwarded, (both sides are IN/OUT), only one direction
561 * may be locked.
563 struct mutex rcv_lock;
565 unsigned long jiffies_credit_update;
566 struct list_head credit_list;
567 /* state */
568 __s64 credits;
569 __u32 credits_fract;
570 /* credit rates, locked by credit_lock (in credit.c) */
571 __u32 sender_crate;
572 __u32 recp_crate;
574 * This is how much we *want* to forward, but how much we actually do.
575 * 2^32 == 100%
577 __u32 crate_forward;
579 union{
580 struct{
581 struct neighbor *nb;
582 /* list of all connections from this neighbor */
583 struct list_head nb_list;
585 struct sk_buff_head reorder_queue;
587 struct htab_entry htab_entry;
588 __u32 conn_id;
589 __u32 next_seqno;
590 __u32 ooo_packets;
592 atomic_t pong_awaiting;
594 /* credit rate */
595 __u32 crate_in_raw;
597 __u32 window_seqnolimit_max;
598 __u32 window_seqnolimit_last;
600 struct list_head buffer_list;
602 __u32 buffer_init;
603 __u32 buffer_speed;
604 __u32 buffer_ata;
606 __u32 usage_init;
607 __u32 usage_speed;
608 __u32 usage_ata;
609 __u32 usage_reserve;
611 struct speedtracker st;
613 unsigned long jiffies_last_window_set;
614 }in;
616 struct{
617 struct list_head cl_list;
618 wait_queue_head_t wait;
619 struct socket *sock;
620 int flags;
622 __u32 crate;
623 __u32 alloclimit;
624 struct sock_buffertracker *sbt;
625 struct list_head delflush_list;
626 struct list_head alwait_list;
627 __u8 in_alwait_list;
628 __u8 delay_flush;
629 __u32 wait_len;
630 }sock;
631 }source;
633 union{
634 struct{
635 __u32 paramlen;
636 __u32 cmdread;
637 __u16 cmd;
638 __u8 paramlen_read;
639 __u8 *cmdparams;
640 char paramlen_buf[4];
642 __u8 in_buffer_wait_list;
643 struct list_head buffer_wait_list;
645 __u32 stall_timeout_ms;
646 }unconnected;
648 struct{
649 /* has to be first (because it is first in target
650 * kernel too)
652 struct neighbor *nb;
653 /* list of all connections to this neighbor */
654 struct list_head nb_list;
655 /* protected by nb->retrans_lock, sorted by seqno */
656 struct list_head retrans_list;
658 /* reverse conn_id lookup */
659 struct htab_entry htab_entry;
661 __u32 conn_id;
662 __u32 seqno_nextsend;
663 __u32 seqno_acked;
664 __u32 seqno_windowlimit;
665 __u32 kp_windowsetseqno;
667 struct resume_block rb;
669 __u32 stall_timeout_ms;
671 /* credit rate */
672 long jiffies_crate_send;
673 __u32 crate_out_raw;
674 }out;
676 struct{
677 wait_queue_head_t wait;
679 __u8 credituser;
680 }sock;
681 }target;
683 struct{
684 struct list_head items;
685 struct data_buf_item *lastread;
686 __u32 first_offset;
688 __u32 totalsize;
689 __u32 overhead;
690 __u32 read_remaining;
692 __u16 last_read_offset;
694 __u16 cpacket_buffer;/* including overhead */
695 }data_buf;
697 struct conn *reversedir;
700 /* inside skb->cb */
701 struct skb_procstate{
702 union{
703 struct{
704 struct work_struct work;
705 }rcv;
707 struct{
708 __u32 offset;
709 }announce;
711 struct{
712 __u32 seqno;
713 }rcv2;
714 }funcstate;
717 struct sock_buffertracker {
718 struct list_head lh;
720 uid_t uid;
721 __u64 usage;
723 struct list_head delflush_conns;
724 struct list_head waiting_conns;
726 struct kref ref;
730 /* common.c */
731 extern atomic_t num_conns;
733 extern __u8 enc_window(__u32 window_bytes);
735 extern __u32 dec_window(__u8 window);
737 extern char *htable_get(struct htable *ht, __u32 key, void *searcheditem);
739 extern int htable_delete(struct htable *ht, __u32 key, void *searcheditem,
740 void (*free) (struct kref *ref));
742 extern void htable_insert(struct htable *ht, char *newelement, __u32 key);
744 extern void htable_init(struct htable *ht, int (*matches)(void *htentry,
745 void *searcheditem), __u32 entry_offset,
746 __u32 kref_offset);
748 extern struct conn *get_conn_reverse(struct neighbor *nb, __u32 conn_id);
750 extern void insert_reverse_connid(struct conn *rconn);
752 extern struct conn *get_conn(__u32 conn_id);
754 extern void free_conn(struct kref *ref);
756 extern int conn_init_out(struct conn *rconn, struct neighbor *nb);
758 extern void conn_init_sock_source(struct conn *conn);
760 extern void conn_init_sock_target(struct conn *conn);
762 extern void close_port(struct connlistener *listener);
764 extern struct connlistener *open_port(__be64 port);
766 extern int connect_port(struct conn *rconn, __be64 port);
768 extern int connect_neigh(struct conn *rconn,
769 __u16 addrtypelen, __u8 *addrtype,
770 __u16 addrlen, __u8 *addr);
772 extern struct conn* alloc_conn(gfp_t allocflags);
774 extern void reset_ping(struct conn *rconn);
776 extern void reset_conn(struct conn *conn);
778 /* credits.c */
779 extern int refresh_credits_state(struct neighbor *nb);
781 extern void check_credit_state(struct neighbor *nb);
783 extern int debit_adj_needed(struct neighbor *nb);
785 extern int refresh_conn_credits(struct conn *conn, int fromperiodic);
787 extern void set_credits(struct neighbor *nb, __u64 credits,
788 __s32 creditrate_initial, __u32 creditrate_earning,
789 __u32 creditrate_spending);
791 extern void set_debitrate_initial(struct neighbor *nb, __u32 debitrate);
793 extern void set_conn_in_crate(struct conn *rconn, __u32 crate_in);
795 extern void connreset_credits(struct conn *conn);
797 extern void credits_init(void);
799 /* neighbor.c */
800 extern void neighbor_free(struct kref *ref);
802 extern struct neighbor *get_neigh_by_mac(struct sk_buff *skb);
804 extern struct neighbor *find_neigh(__u16 addrtypelen, __u8 *addrtype,
805 __u16 addrlen, __u8 *addr);
807 extern __u32 generate_neigh_list(char *buf, __u32 buflen, __u32 limit,
808 __u32 offset);
810 extern int get_neigh_state(struct neighbor *nb);
812 extern void ping_resp(struct neighbor *nb, __u32 cookie, __u32 respdelay);
814 extern __u32 add_ping_req(struct neighbor *nb);
816 extern void unadd_ping_req(struct neighbor *nb, __u32 cookie);
818 extern int time_to_send_ping(struct neighbor *nb);
820 extern int force_ping(struct neighbor *nb);
822 extern void rcv_announce(struct sk_buff *skb);
824 extern int send_announce_qos(struct announce_data *ann);
826 extern void announce_data_free(struct kref *ref);
828 extern int __init cor_neighbor_init(void);
830 /* rcv.c */
831 extern __u8 get_window(struct conn *rconn);
833 extern void reset_bufferusage(struct conn *conn);
835 extern void refresh_speedstat(struct conn *rconn, __u32 written);
837 extern void drain_ooo_queue(struct conn *rconn);
839 extern void conn_rcv_buildskb(char *data, __u32 datalen, __u32 conn_id,
840 __u32 seqno);
842 extern int __init cor_rcv_init(void);
844 /* kpacket_parse.c */
845 extern void kernel_packet(struct neighbor *nb, struct sk_buff *skb, __u32 seqno);
847 /* kpacket_gen.c */
848 extern void schedule_controlmsg_timerfunc(struct neighbor *nb);
850 struct control_msg_out;
852 #define ACM_PRIORITY_LOW 1
853 #define ACM_PRIORITY_MED 2
854 #define ACM_PRIORITY_HIGH 3
856 extern int may_alloc_control_msg(struct neighbor *nb, int priority);
858 extern struct control_msg_out *alloc_control_msg(struct neighbor *nb,
859 int priority);
861 extern void free_control_msg(struct control_msg_out *cm);
863 extern void retransmit_timerfunc(struct work_struct *work);
865 extern void kern_ack_rcvd(struct neighbor *nb, __u32 seqno);
867 extern int send_messages(struct neighbor *nb, int allmsgs, int resume);
869 extern void send_pong(struct neighbor *nb,
870 __u32 cookie);
872 extern void send_reset_conn(struct control_msg_out *cm, __u32 conn_id);
874 extern void send_ack(struct neighbor *nb,
875 __u32 seqno);
877 extern void send_ack_conn(struct control_msg_out *cm, struct conn *rconn,
878 __u32 conn_id, __u32 seqno);
880 extern void send_ack_conn_ooo(struct control_msg_out *cm, struct conn *rconn,
881 __u32 conn_id, __u32 seqno, __u32 seqno_ooo, __u32 length);
883 extern void send_connect_success(struct control_msg_out *cm, __u32 rcvd_conn_id,
884 __u32 gen_conn_id, __u32 init_seqno, struct conn *rconn);
886 extern void send_connect_nb(struct control_msg_out *cm, __u32 conn_id,
887 __u32 init_seqno, struct conn *sconn);
889 extern void send_conndata(struct control_msg_out *cm, __u32 conn_id,
890 __u32 seqno, char *data_orig, char *data, __u32 datalen);
892 extern void send_ping_conn(struct control_msg_out *cm, __u32 conn_id);
894 extern void send_connid_unknown(struct control_msg_out *cm, __u32 conn_id);
896 extern void send_ping_all_conns(struct neighbor *nb);
898 extern void send_credits(struct neighbor *nb);
900 extern void cor_kgen_init(void);
902 /* cpacket_parse.c */
903 extern void free_cpacket_buffer(__s32 amount);
905 extern void connreset_cpacket_buffer(struct conn *rconn);
907 extern int encode_len(char *buf, int buflen, __u32 len);
909 extern int decode_len(char *buf, int buflen, __u32 *len);
911 extern void parse(struct conn *rconn, int fromresume);
913 extern int __init cor_cpacket_init(void);
915 /* snd.c */
916 extern int destroy_queue(struct net_device *dev);
918 extern int create_queue(struct net_device *dev);
920 #define QOS_CALLER_KPACKET 0
921 #define QOS_CALLER_CONN_RETRANS 1
922 #define QOS_CALLER_ANNOUNCE 2
923 #define QOS_CALLER_CONN 3
925 extern void qos_enqueue(struct net_device *dev, struct resume_block *rb,
926 int caller);
928 extern void qos_remove_conn(struct conn *rconn);
930 extern struct sk_buff *create_packet(struct neighbor *nb, int size,
931 gfp_t alloc_flags, __u32 conn_id, __u32 seqno);
933 extern void cancel_retrans(struct conn *rconn);
935 extern void retransmit_conn_timerfunc(struct work_struct *work);
937 extern void conn_ack_rcvd(__u32 kpacket_seqno, struct conn *rconn, __u32 seqno,
938 __u8 window, __u32 seqno_ooo, __u32 length);
940 #define RC_FLUSH_CONN_OUT_OK 0
941 #define RC_FLUSH_CONN_OUT_OK_SENT 1
942 #define RC_FLUSH_CONN_OUT_CONG 2
943 #define RC_FLUSH_CONN_OUT_CREDITS 3
944 #define RC_FLUSH_CONN_OUT_OOM 4
945 extern int flush_out(struct conn *rconn, int fromqos, __u32 creditsperbyte);
947 extern int __init cor_snd_init(void);
949 /* forward.c */
950 extern void databuf_pull(struct conn *conn, char *dst, int len);
952 extern size_t databuf_pulluser(struct conn *sconn, struct msghdr *msg);
954 extern void databuf_unpull(struct conn *conn, __u32 bytes);
956 extern void databuf_pullold(struct conn *conn, __u32 startpos, char *dst,
957 int len);
959 extern void databuf_ack(struct conn *rconn, __u32 pos);
961 extern void databuf_ackread(struct conn *rconn);
963 extern void flush_buf(struct conn *rconn);
965 extern void reset_seqno(struct conn *conn, __u32 initseqno);
967 extern void databuf_free(struct conn *conn);
969 extern void databuf_init(struct conn *conn);
971 __s64 receive_userbuf(struct conn *rconn, struct msghdr *msg, __u32 maxcpy,
972 __u32 maxusage);
974 extern void receive_cpacketresp(struct conn *rconn, char *buf, int len);
976 extern int receive_skb(struct conn *rconn, struct sk_buff *skb);
978 extern void wake_sender(struct conn *rconn);
980 extern void forward_init(void);
982 /* sock.c */
983 extern struct mutex sock_bufferlimits_lock;
985 extern void free_sbt(struct kref *ref);
987 extern void unreserve_sock_buffer(struct conn *conn);
990 static inline struct skb_procstate *skb_pstate(struct sk_buff *skb)
992 return (struct skb_procstate *) &(skb->cb[0]);
995 static inline struct sk_buff *skb_from_pstate(struct skb_procstate *ps)
997 return (struct sk_buff *) (((char *)ps) - offsetof(struct sk_buff,cb));
1001 static inline __u32 mss(struct neighbor *nb)
1003 return nb->dev->mtu - LL_RESERVED_SPACE(nb->dev) - 9;
1007 static inline void put_u64(char *dst, __u64 value, int convbo)
1009 char *p_value = (char *) &value;
1011 if (convbo)
1012 value = cpu_to_be64(value);
1014 dst[0] = p_value[0];
1015 dst[1] = p_value[1];
1016 dst[2] = p_value[2];
1017 dst[3] = p_value[3];
1018 dst[4] = p_value[4];
1019 dst[5] = p_value[5];
1020 dst[6] = p_value[6];
1021 dst[7] = p_value[7];
1024 static inline void put_u32(char *dst, __u32 value, int convbo)
1026 char *p_value = (char *) &value;
1028 if (convbo)
1029 value = cpu_to_be32(value);
1031 dst[0] = p_value[0];
1032 dst[1] = p_value[1];
1033 dst[2] = p_value[2];
1034 dst[3] = p_value[3];
1037 static inline void put_u16(char *dst, __u16 value, int convbo)
1039 char *p_value = (char *) &value;
1041 if (convbo)
1042 value = cpu_to_be16(value);
1044 dst[0] = p_value[0];
1045 dst[1] = p_value[1];
1048 static inline char *cor_pull_skb(struct sk_buff *skb, unsigned int len)
1050 char *ptr = skb_pull(skb, len);
1052 if(unlikely(ptr == 0))
1053 return 0;
1055 return ptr - len;
1059 static inline __u64 mul_saturated(__u64 a, __u64 b)
1061 __u64 res = a*b;
1062 if (res / a != b)
1063 return -1;
1064 return res;
1067 static inline int numdigits(__u64 value)
1069 int digits = 0;
1070 for (;value != 0;value = (value >> 1)) {
1071 digits++;
1073 return digits;
1076 /* approximate (a*b) / c without overflowing a*b */
1077 static inline __u64 multiply_div(__u64 a, __u64 b, __u64 c)
1079 int alen = numdigits(a);
1080 int blen = numdigits(b);
1081 int clen = numdigits(c);
1083 BUG_ON(alen < 0 || alen > 64);
1084 BUG_ON(blen < 0 || blen > 64);
1085 BUG_ON(clen < 0 || clen > 64);
1087 BUG_ON((a == 0 && alen != 0) || (a != 0 && alen == 0));
1088 BUG_ON((b == 0 && blen != 0) || (b != 0 && blen == 0));
1089 BUG_ON((c == 0 && clen != 0) || (c != 0 && clen == 0));
1091 BUG_ON(a >= b && alen < blen);
1092 BUG_ON(a >= c && alen < clen);
1093 BUG_ON(b >= a && blen < alen);
1094 BUG_ON(b >= c && blen < clen);
1095 BUG_ON(c >= a && clen < alen);
1096 BUG_ON(c >= b && clen < blen);
1098 if (alen == 0 || blen == 0)
1099 return 0;
1101 BUG_ON(c == 0);
1103 if (alen + blen <= 64)
1104 return (a*b)/c;
1106 if (a >= b && alen > clen + 16)
1107 return mul_saturated(a/c, b);
1108 else if (a < b && blen > clen + 16)
1109 return mul_saturated(b/c, a);
1111 while (alen + blen > 64) {
1112 if (alen > blen || (alen == blen && a > b)) {
1113 alen--;
1114 a = (a >> 1);
1115 } else {
1116 blen--;
1117 b = (b >> 1);
1119 clen--;
1120 c = (c >> 1);
1123 return (a*b)/c;