2 * Connection oriented routing
3 * Copyright (C) 2007-2009 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
24 * Splited packet data format:
25 * announce proto version [4]
26 * is 0, may be increased if format changes
28 * starts with 0, increments every time the data field changes
30 * total data size of all merged packets
32 * used to determine the order when merging the split packet
35 * commulative checksum [8] (not yet)
36 * chunk 1 contains the checksum of the data in chunk 1
37 * chunk 2 contains the checksum of the data in chunk 1+2
40 * Data format of the announce packet "data" field:
41 * min_announce_proto_version [4]
42 * max_announce_proto_version [4]
43 * min_cor_proto_version [4]
44 * max_cor_proto_version [4]
45 * versions which are understood
49 * commanddata [commandlength]
54 #define NEIGHCMD_ADDADDR 1
59 * addrtype [addrtypelen]
66 * "I hear you" data format:
71 DEFINE_MUTEX(neighbor_operation_lock
);
73 char *addrtype
= "id";
79 struct kmem_cache
*nb_slab
;
81 LIST_HEAD(announce_out_list
);
83 struct notifier_block netdev_notify
;
86 #define ADDRTYPE_UNKNOWN 0
89 static int get_addrtype(__u32 addrtypelen
, char *addrtype
)
91 if (addrtypelen
== 2 &&
92 (addrtype
[0] == 'i' || addrtype
[0] == 'I') &&
93 (addrtype
[1] == 'd' || addrtype
[1] == 'D'))
96 return ADDRTYPE_UNKNOWN
;
99 static void neighbor_free(struct ref_counter
*ref
)
101 struct neighbor
*nb
= container_of(ref
, struct neighbor
, refs
);
102 BUG_ON(nb
->nb_list
.next
!= 0 || nb
->nb_list
.prev
!= 0);
109 kmem_cache_free(nb_slab
, nb
);
112 static struct ref_counter_def neighbor_ref
= {
113 .free
= neighbor_free
116 static struct neighbor
*alloc_neighbor(gfp_t allocflags
)
118 struct neighbor
*nb
= kmem_cache_alloc(nb_slab
, allocflags
);
125 memset(nb
, 0, sizeof(struct neighbor
));
127 ref_counter_init(&(nb
->refs
), &neighbor_ref
);
128 mutex_init(&(nb
->cmsg_lock
));
129 INIT_LIST_HEAD(&(nb
->control_msgs_out
));
130 nb
->last_ping_time
= jiffies
;
131 atomic_set(&(nb
->ooo_packets
), 0);
132 get_random_bytes((char *) &seqno
, sizeof(seqno
));
133 atomic_set(&(nb
->kpacket_seqno
), seqno
);
134 atomic_set(&(nb
->latency
), 0);
135 mutex_init(&(nb
->conn_list_lock
));
136 INIT_LIST_HEAD(&(nb
->rcv_conn_list
));
137 INIT_LIST_HEAD(&(nb
->snd_conn_list
));
138 spin_lock_init(&(nb
->retrans_lock
));
139 spin_lock_init(&(nb
->retrans_lock
));
140 skb_queue_head_init(&(nb
->retrans_list
));
145 struct neighbor
*get_neigh_by_mac(struct sk_buff
*skb
)
147 struct list_head
*currlh
;
148 struct neighbor
*ret
= 0;
151 char source_hw
[MAX_ADDR_LEN
];
152 memset(source_hw
, 0, MAX_ADDR_LEN
);
153 if (skb
->dev
->header_ops
!= 0 &&
154 skb
->dev
->header_ops
->parse
!= 0)
155 skb
->dev
->header_ops
->parse(skb
, source_hw
);
157 mutex_lock(&(neighbor_operation_lock
));
159 currlh
= nb_list
.next
;
161 while (currlh
!= &nb_list
) {
162 struct neighbor
*curr
= container_of(currlh
, struct neighbor
,
165 if (memcmp(curr
->mac
, source_hw
, MAX_ADDR_LEN
) == 0) {
167 ref_counter_incr(&(ret
->refs
));
172 currlh
= currlh
->next
;
176 mutex_unlock(&(neighbor_operation_lock
));
181 struct neighbor
*find_neigh(__u16 addrtypelen
, __u8
*addrtype
,
182 __u16 addrlen
, __u8
*addr
)
184 struct list_head
*currlh
;
185 struct neighbor
*ret
= 0;
187 if (get_addrtype(addrtypelen
, addrtype
) != ADDRTYPE_ID
)
190 mutex_lock(&(neighbor_operation_lock
));
192 currlh
= nb_list
.next
;
194 while (currlh
!= &nb_list
) {
195 struct neighbor
*curr
= container_of(currlh
, struct neighbor
,
198 if (curr
->addrlen
== addrlen
&& memcmp(curr
->addr
, addr
,
201 ref_counter_incr(&(ret
->refs
));
206 currlh
= currlh
->next
;
210 mutex_unlock(&(neighbor_operation_lock
));
215 __u32
generate_neigh_list(char *buf
, __u32 buflen
, __u32 limit
, __u32 offset
)
217 struct list_head
*currlh
;
219 char *p_totalneighs
= buf
;
220 char *p_response_rows
= buf
+ 4;
225 __u32 buf_offset
= 8;
230 mutex_lock(&(neighbor_operation_lock
));
232 currlh
= nb_list
.next
;
234 while (currlh
!= &nb_list
) {
235 struct neighbor
*curr
= container_of(currlh
, struct neighbor
,
241 if (unlikely(buflen
- buf_offset
- 6 - 2 - curr
->addrlen
< 0))
244 put_u16(buf
+ buf_offset
, 1, 1);/* numaddr */
246 put_u16(buf
+ buf_offset
, 2, 1);/* addrtypelen */
248 put_u16(buf
+ buf_offset
, curr
->addrlen
, 1);/* addren */
250 buf
[buf_offset
] = 'i'; /* addrtype */
252 buf
[buf_offset
] = 'd';
254 memcpy(buf
+ buf_offset
, curr
->addr
, curr
->addrlen
); /* addr */
255 buf_offset
+= curr
->addrlen
;
257 BUG_ON(buf_offset
> buflen
);
263 currlh
= currlh
->next
;
266 mutex_unlock(&(neighbor_operation_lock
));
268 put_u32(p_totalneighs
, total
, 1);
269 put_u32(p_response_rows
, cnt
, 1);
274 static struct ping_cookie
*find_cookie(struct neighbor
*nb
, __u32 cookie
)
278 for(i
=0;i
<PING_COOKIES_PER_NEIGH
;i
++) {
279 if (nb
->cookies
[i
].cookie
== cookie
)
280 return &(nb
->cookies
[i
]);
285 void ping_resp(struct neighbor
*nb
, __u32 cookie
, __u32 respdelay
)
287 struct ping_cookie
*c
= find_cookie(nb
, cookie
);
295 newlatency
= ((((__s64
) ((__u32
)atomic_read(&(nb
->latency
)))) * 15 +
296 jiffies_to_usecs(jiffies
- c
->time
) - respdelay
) / 16);
297 if (unlikely(newlatency
< 0))
299 if (unlikely(newlatency
> (((__s64
)256)*256*256*256 - 1)))
300 newlatency
= ((__s64
)256)*256*256*256 - 1;
302 atomic_set(&(nb
->latency
), (__u32
) newlatency
);
305 nb
->ping_intransit
--;
307 for(i
=0;i
<PING_COOKIES_PER_NEIGH
;i
++) {
308 if (nb
->cookies
[i
].cookie
!= 0 &&
309 time_before(nb
->cookies
[i
].time
, c
->time
)) {
310 nb
->cookies
[i
].pongs
++;
311 if (nb
->cookies
[i
].pongs
>= PING_PONGLIMIT
) {
312 nb
->cookies
[i
].cookie
= 0;
313 nb
->cookies
[i
].pongs
= 0;
314 nb
->ping_intransit
--;
320 __u32
add_ping_req(struct neighbor
*nb
)
322 struct ping_cookie
*c
;
325 for (i
=0;i
<PING_COOKIES_PER_NEIGH
;i
++) {
326 if (nb
->cookies
[i
].cookie
== 0)
330 get_random_bytes((char *) &i
, sizeof(i
));
331 i
= i
% (PING_COOKIES_PER_NEIGH
- PING_COOKIES_FIFO
) +
335 c
= &(nb
->cookies
[i
]);
339 if (unlikely(nb
->lastcookie
== 0))
341 c
->cookie
= nb
->lastcookie
;
343 nb
->ping_intransit
++;
350 * Check additional to the checks and timings already done in kpacket_gen.c
351 * This is primarily to make sure that we do not invalidate other ping cookies
352 * which might still receive responses. It does this by requiring a certain
353 * mimimum delay between pings, depending on how many pings are already in
356 int time_to_send_ping(struct neighbor
*nb
)
358 if (nb
->ping_intransit
>= PING_COOKIES_NOTHROTTLE
) {
359 __u32 mindelay
= (((__u32
)atomic_read(&(nb
->latency
)))/1000) <<
360 (nb
->ping_intransit
+ 1 -
361 PING_COOKIES_NOTHROTTLE
);
362 if (mindelay
> PING_THROTTLE_LIMIT_MS
)
363 mindelay
= PING_THROTTLE_LIMIT_MS
;
365 if (jiffies_to_msecs(jiffies
- nb
->last_ping_time
) < mindelay
)
372 static void add_neighbor(struct neighbor
*nb
)
374 struct list_head
*currlh
= nb_list
.next
;
376 BUG_ON((nb
->addr
== 0) != (nb
->addrlen
== 0));
378 while (currlh
!= &nb_list
) {
379 struct neighbor
*curr
= container_of(currlh
, struct neighbor
,
382 if (curr
->addrlen
== nb
->addrlen
&& memcmp(curr
->addr
, nb
->addr
,
384 goto already_present
;
386 currlh
= currlh
->next
;
389 list_add_tail(&(nb
->nb_list
), &nb_list
);
390 schedule_controlmsg_timerfunc(nb
);
391 setup_timer(&(nb
->retrans_timer
), retransmit_timerfunc
,
396 kmem_cache_free(nb_slab
, nb
);
400 static __u32
pull_u32(struct sk_buff
*skb
, int convbo
)
402 char *ptr
= cor_pull_skb(skb
, 4);
408 ((char *)&ret
)[0] = ptr
[0];
409 ((char *)&ret
)[1] = ptr
[1];
410 ((char *)&ret
)[2] = ptr
[2];
411 ((char *)&ret
)[3] = ptr
[3];
414 return be32_to_cpu(ret
);
418 static int apply_announce_addaddr(struct neighbor
*nb
, __u32 cmd
, __u32 len
,
426 BUG_ON((nb
->addr
== 0) != (nb
->addrlen
== 0));
434 addrtypelen
= be16_to_cpu(*((__u16
*) cmddata
));
441 addrlen
= be16_to_cpu(*((__u16
*) cmddata
));
446 cmddata
+= addrtypelen
;
456 if (get_addrtype(addrtypelen
, addrtype
) != ADDRTYPE_ID
)
459 nb
->addr
= kmalloc(addrlen
, GFP_KERNEL
);
463 memcpy(nb
->addr
, addr
, addrlen
);
464 nb
->addrlen
= addrlen
;
469 static void apply_announce_cmd(struct neighbor
*nb
, __u32 cmd
, __u32 len
,
472 if (cmd
== NEIGHCMD_ADDADDR
) {
473 apply_announce_addaddr(nb
, cmd
, len
, cmddata
);
475 /* ignore unknown cmds */
479 static void apply_announce_cmds(char *msg
, __u32 len
, struct net_device
*dev
,
482 struct neighbor
*nb
= alloc_neighbor(GFP_KERNEL
);
491 cmd
= be32_to_cpu(*((__u32
*) msg
));
494 cmdlen
= be32_to_cpu(*((__u32
*) msg
));
498 BUG_ON(cmdlen
> len
);
500 apply_announce_cmd(nb
, cmd
, cmdlen
, msg
);
508 memcpy(nb
->mac
, source_hw
, MAX_ADDR_LEN
);
516 static int check_announce_cmds(char *msg
, __u32 len
)
522 cmd
= be32_to_cpu(*((__u32
*) msg
));
525 cmdlen
= be32_to_cpu(*((__u32
*) msg
));
529 /* malformated packet */
543 static void parse_announce(char *msg
, __u32 len
, struct net_device
*dev
,
546 __u32 min_announce_version
;
547 __u32 max_announce_version
;
548 __u32 min_cor_version
;
549 __u32 max_cor_version
;
554 min_announce_version
= be32_to_cpu(*((__u32
*) msg
));
557 max_announce_version
= be32_to_cpu(*((__u32
*) msg
));
560 min_cor_version
= be32_to_cpu(*((__u32
*) msg
));
563 max_cor_version
= be32_to_cpu(*((__u32
*) msg
));
567 if (min_announce_version
!= 0)
569 if (min_cor_version
!= 0)
571 if (check_announce_cmds(msg
, len
)) {
574 apply_announce_cmds(msg
, len
, dev
, source_hw
);
578 /* lh has to be first */
580 struct sk_buff_head skbs
; /* sorted by offset */
581 struct net_device
*dev
;
582 char source_hw
[MAX_ADDR_LEN
];
583 __u32 announce_proto_version
;
584 __u32 packet_version
;
587 __u64 last_received_packet
;
590 LIST_HEAD(announce_list
);
592 struct kmem_cache
*announce_in_slab
;
594 static void merge_announce(struct announce_in
*ann
)
596 char *msg
= kmalloc(ann
->total_size
, GFP_KERNEL
);
600 /* try again when next packet arrives */
604 while (copy
!= ann
->total_size
) {
608 if (skb_queue_empty(&(ann
->skbs
))) {
609 printk(KERN_ERR
"net/cor/neighbor.c: sk_head ran "
610 "empty while merging packets\n");
614 skb
= skb_dequeue(&(ann
->skbs
));
618 if (currcpy
+ copy
> ann
->total_size
)
621 #warning todo overlapping skbs
622 memcpy(msg
+ copy
, skb
->data
, currcpy
);
627 parse_announce(msg
, ann
->total_size
, ann
->dev
, ann
->source_hw
);
634 list_del(&(ann
->lh
));
635 kmem_cache_free(announce_in_slab
, ann
);
638 static int _rcv_announce(struct sk_buff
*skb
, struct announce_in
*ann
)
640 struct skb_procstate
*ps
= skb_pstate(skb
);
642 __u32 offset
= ps
->funcstate
.announce
.offset
;
643 __u32 len
= skb
->len
;
645 __u32 curroffset
= 0;
646 __u32 prevoffset
= 0;
649 struct sk_buff
*curr
= ann
->skbs
.next
;
651 if (len
+ offset
> ann
->total_size
) {
658 * Try to find the right place to insert in the sorted list. This
659 * means to process the list until we find a skb which has a greater
660 * offset, so we can insert before it to keep the sort order. However,
661 * this is complicated by the fact that the new skb must not be inserted
662 * between 2 skbs if there is no data missing in between. So the loop
663 * runs has to keep running until there is either a gap to insert or
664 * we see that this data has already been received.
666 while ((void *) curr
!= (void *) &(ann
->skbs
)) {
667 struct skb_procstate
*currps
= skb_pstate(skb
);
669 curroffset
= currps
->funcstate
.announce
.offset
;
671 if (curroffset
> offset
&& (prevoffset
+ prevlen
) < curroffset
)
674 prevoffset
= curroffset
;
678 if ((offset
+len
) <= (prevoffset
+prevlen
)) {
679 /* we already have this data */
686 * Calculate how much data was really received, by substracting
687 * the bytes we already have.
689 if (unlikely(prevoffset
+ prevlen
> offset
)) {
690 len
-= (prevoffset
+ prevlen
) - offset
;
691 offset
= prevoffset
+ prevlen
;
694 if (unlikely((void *) curr
!= (void *) &(ann
->skbs
) &&
695 (offset
+ len
) > curroffset
))
696 len
= curroffset
- offset
;
698 ann
->received_size
+= len
;
699 BUG_ON(ann
->received_size
> ann
->total_size
);
700 __skb_queue_before(&(ann
->skbs
), curr
, skb
);
701 ann
->last_received_packet
= get_jiffies_64();
703 if (ann
->received_size
== ann
->total_size
)
705 else if (ann
->skbs
.qlen
>= 16)
711 void rcv_announce(struct sk_buff
*skb
)
713 struct skb_procstate
*ps
= skb_pstate(skb
);
714 struct announce_in
*curr
= 0;
715 struct announce_in
*leastactive
= 0;
718 __u32 announce_proto_version
= pull_u32(skb
, 1);
719 __u32 packet_version
= pull_u32(skb
, 1);
720 __u32 total_size
= pull_u32(skb
, 1);
722 char source_hw
[MAX_ADDR_LEN
];
723 memset(source_hw
, 0, MAX_ADDR_LEN
);
724 if (skb
->dev
->header_ops
!= 0 &&
725 skb
->dev
->header_ops
->parse
!= 0)
726 skb
->dev
->header_ops
->parse(skb
, source_hw
);
728 ps
->funcstate
.announce
.offset
= pull_u32(skb
, 1);
730 if (total_size
> 8192)
733 mutex_lock(&(neighbor_operation_lock
));
735 if (announce_proto_version
!= 0)
738 curr
= (struct announce_in
*) announce_list
.next
;
740 while (((struct list_head
*) curr
) != &(announce_list
)) {
742 if (curr
->dev
== skb
->dev
&&
743 memcmp(curr
->source_hw
, source_hw
, MAX_ADDR_LEN
) == 0 &&
744 curr
->announce_proto_version
== announce_proto_version
&&
745 curr
->packet_version
== packet_version
&&
746 curr
->total_size
== total_size
)
749 if (leastactive
== 0 || curr
->last_received_packet
<
750 leastactive
->last_received_packet
)
753 curr
= (struct announce_in
*) curr
->lh
.next
;
756 if (list_size
>= 128) {
757 BUG_ON(leastactive
== 0);
760 curr
->last_received_packet
= get_jiffies_64();
762 while (!skb_queue_empty(&(curr
->skbs
))) {
763 struct sk_buff
*skb2
= skb_dequeue(&(curr
->skbs
));
769 curr
= kmem_cache_alloc(announce_in_slab
,
774 skb_queue_head_init(&(curr
->skbs
));
775 list_add_tail((struct list_head
*) curr
, &announce_list
);
778 curr
->packet_version
= packet_version
;
779 curr
->total_size
= total_size
;
780 curr
->received_size
= 0;
781 curr
->announce_proto_version
= announce_proto_version
;
782 curr
->dev
= skb
->dev
;
784 memcpy(curr
->source_hw
, source_hw
, MAX_ADDR_LEN
);
787 if (_rcv_announce(skb
, curr
)) {
788 list_del((struct list_head
*) curr
);
790 kmem_cache_free(announce_in_slab
, curr
);
798 mutex_unlock(&(neighbor_operation_lock
));
802 struct ref_counter refs
;
804 __u32 packet_version
;
806 __u32 announce_msg_len
;
809 struct announce
*last_announce
;
811 struct announce_data
{
812 struct delayed_work announce_work
;
814 struct net_device
*dev
;
816 struct announce
*ann
;
820 __u32 curr_announce_msg_offset
;
821 __u64 scheduled_announce_timer
;
824 static void _splitsend_announce(struct announce_data
*ann
)
827 __u32 packet_size
= 256;
828 __u32 remainingdata
= ann
->ann
->announce_msg_len
-
829 ann
->curr_announce_msg_offset
;
830 __u32 headroom
= LL_ALLOCATED_SPACE(ann
->dev
);
831 __u32 overhead
= 17 + headroom
;
835 if (remainingdata
< packet_size
)
836 packet_size
= remainingdata
;
838 skb
= alloc_skb(packet_size
+ overhead
, GFP_KERNEL
);
839 if (unlikely(0 == skb
))
842 skb
->protocol
= htons(ETH_P_COR
);
844 skb_reserve(skb
, headroom
);
846 if(unlikely(dev_hard_header(skb
, ann
->dev
, ETH_P_COR
,
847 ann
->dev
->broadcast
, ann
->dev
->dev_addr
, skb
->len
) < 0))
850 skb_reset_network_header(skb
);
852 header
= skb_put(skb
, 17);
853 if (unlikely(header
== 0))
856 header
[0] = PACKET_TYPE_ANNOUNCE
;
858 put_u32(header
+ 1, 0, 1); /* announce proto version */
859 put_u32(header
+ 5, ann
->ann
->packet_version
, 1); /* packet version */
860 put_u32(header
+ 9, ann
->ann
->announce_msg_len
, 1); /* total size */
861 put_u32(header
+ 13, ann
->curr_announce_msg_offset
, 1); /* offset */
863 ptr
= skb_put(skb
, packet_size
);
864 if (unlikely(ptr
== 0))
867 memcpy(ptr
, ann
->ann
->announce_msg
+ ann
->curr_announce_msg_offset
, packet_size
);
870 ann
->curr_announce_msg_offset
+= packet_size
;
872 if (ann
->curr_announce_msg_offset
== ann
->ann
->announce_msg_len
)
873 ann
->curr_announce_msg_offset
= 0;
882 static void splitsend_announce(struct work_struct
*work
)
884 struct announce_data
*ann
= container_of(to_delayed_work(work
),
885 struct announce_data
, announce_work
);
888 mutex_lock(&(neighbor_operation_lock
));
895 if (ann
->ann
== 0 && last_announce
== 0)
898 if (ann
->curr_announce_msg_offset
== 0 && ann
->ann
!= last_announce
) {
900 ref_counter_decr(&(ann
->ann
->refs
));
901 ann
->ann
= last_announce
;
902 ref_counter_incr(&(ann
->ann
->refs
));
905 _splitsend_announce(ann
);
907 mutex_unlock(&(neighbor_operation_lock
));
910 int target_delay_ms
= 500;
911 int target_delay_jiffies
= msecs_to_jiffies(target_delay_ms
);
912 __u64 jiffies
= get_jiffies_64();
915 ann
->scheduled_announce_timer
+= target_delay_jiffies
;
917 delay
= ann
->scheduled_announce_timer
- jiffies
;
921 INIT_DELAYED_WORK(&(ann
->announce_work
), splitsend_announce
);
922 schedule_delayed_work(&(ann
->announce_work
), delay
);
926 static void announce_free(struct ref_counter
*ref
)
928 struct announce
*ann
= container_of(ref
, struct announce
, refs
);
929 kfree(&(ann
->announce_msg
));
933 static struct ref_counter_def announce_ref
= {
934 .free
= announce_free
937 static struct announce_data
*get_announce_by_netdev(struct net_device
*dev
)
939 struct list_head
*lh
= announce_out_list
.next
;
941 while (lh
!= &announce_out_list
) {
942 struct announce_data
*curr
= (struct announce_data
*)(
944 offsetof(struct announce_data
, lh
));
946 if (curr
->dev
== dev
)
953 static void announce_sent_adddev(struct net_device
*dev
)
955 struct announce_data
*ann
;
957 ann
= kmalloc(sizeof(struct announce_data
), GFP_KERNEL
);
960 printk(KERN_ERR
"cor cannot allocate memory for sending "
965 memset(ann
, 0, sizeof(struct announce_data
));
970 mutex_lock(&(neighbor_operation_lock
));
971 list_add_tail(&(ann
->lh
), &announce_out_list
);
972 mutex_unlock(&(neighbor_operation_lock
));
974 ann
->scheduled_announce_timer
= get_jiffies_64();
975 INIT_DELAYED_WORK(&(ann
->announce_work
), splitsend_announce
);
976 schedule_delayed_work(&(ann
->announce_work
), 1);
979 static void announce_sent_rmdev(struct net_device
*dev
)
981 struct announce_data
*ann
;
983 mutex_lock(&(neighbor_operation_lock
));
985 ann
= get_announce_by_netdev(dev
);
994 mutex_unlock(&(neighbor_operation_lock
));
997 int netdev_notify_func(struct notifier_block
*not, unsigned long event
,
1000 struct net_device
*dev
= (struct net_device
*) ptr
;
1004 announce_sent_adddev(dev
);
1007 announce_sent_rmdev(dev
);
1011 case NETDEV_REGISTER
:
1012 case NETDEV_UNREGISTER
:
1013 case NETDEV_CHANGEMTU
:
1014 case NETDEV_CHANGEADDR
:
1015 case NETDEV_GOING_DOWN
:
1016 case NETDEV_CHANGENAME
:
1017 case NETDEV_FEAT_CHANGE
:
1018 case NETDEV_BONDING_FAILOVER
:
1027 static int set_announce(char *msg
, __u32 len
)
1029 struct announce
*ann
= kmalloc(sizeof(struct announce
), GFP_KERNEL
);
1036 memset(ann
, 0, sizeof(struct announce
));
1038 ann
->announce_msg
= msg
;
1039 ann
->announce_msg_len
= len
;
1041 ref_counter_init(&(ann
->refs
), &announce_ref
);
1043 mutex_lock(&(neighbor_operation_lock
));
1045 if (last_announce
!= 0) {
1046 ann
->packet_version
= last_announce
->packet_version
+ 1;
1047 ref_counter_decr(&(last_announce
->refs
));
1050 last_announce
= ann
;
1052 mutex_unlock(&(neighbor_operation_lock
));
1057 static int generate_announce(void)
1059 __u32 addrtypelen
= strlen(addrtype
);
1062 __u32 cmd_hdr_len
= 8;
1063 __u32 cmd_len
= 2 + 2 + addrtypelen
+ addrlen
;
1065 __u32 len
= hdr_len
+ cmd_hdr_len
+ cmd_len
;
1068 char *msg
= kmalloc(len
, GFP_KERNEL
);
1072 put_u32(msg
+ offset
, 0, 1); /* min_announce_proto_version */
1074 put_u32(msg
+ offset
, 0, 1); /* max_announce_proto_version */
1076 put_u32(msg
+ offset
, 0, 1); /* min_cor_proto_version */
1078 put_u32(msg
+ offset
, 0, 1); /* max_cor_proto_version */
1082 put_u32(msg
+ offset
, NEIGHCMD_ADDADDR
, 1); /* command */
1084 put_u32(msg
+ offset
, cmd_len
, 1); /* command length */
1087 /* addrtypelen, addrlen */
1088 put_u16(msg
+ offset
, addrtypelen
, 1);
1090 put_u16(msg
+ offset
, addrlen
, 1);
1093 /* addrtype, addr */
1094 memcpy(msg
+ offset
, addrtype
, addrtypelen
);
1095 offset
+= addrtypelen
;
1096 memcpy(msg
+ offset
, addr
, addrlen
);
1099 BUG_ON(offset
!= len
);
1101 return set_announce(msg
, len
);
1104 int __init
cor_neighbor_init(void)
1108 addr
= kmalloc(addrlen
, GFP_KERNEL
);
1112 get_random_bytes(addr
, addrlen
);
1114 nb_slab
= kmem_cache_create("cor_neighbor", sizeof(struct neighbor
), 8,
1116 announce_in_slab
= kmem_cache_create("cor_announce_in",
1117 sizeof(struct announce_in
), 8, 0, 0);
1119 if (generate_announce())
1122 memset(&netdev_notify
, 0, sizeof(netdev_notify
));
1123 netdev_notify
.notifier_call
= netdev_notify_func
;
1124 register_netdevice_notifier(&netdev_notify
);
1135 MODULE_LICENSE("GPL");