2 * Connection oriented routing
3 * Copyright (C) 2007-2021 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
23 static DEFINE_MUTEX(cor_config_lock
);
25 DEFINE_SPINLOCK(cor_local_addr_lock
);
27 __u32 cor_local_addrlen
;
28 __be32 cor_local_addr_sessionid
;
31 static DEFINE_SPINLOCK(cor_interface_config_lock
);
32 static struct cor_interface_config
*cor_interface_config
= 0;
33 static __u32 cor_num_interfaces
= 0;
34 static int cor_all_interfaces
= 0;
37 int cor_is_device_configurated(struct net_device
*dev
)
44 spin_lock_irqsave(&cor_interface_config_lock
, iflags
);
46 if (cor_all_interfaces
!= 0) {
51 BUG_ON(cor_num_interfaces
> 65536);
52 for (i
=0;i
<cor_num_interfaces
;i
++) {
53 struct cor_interface_config
*curr
= &(cor_interface_config
[i
]);
56 BUG_ON(curr
->name
== 0);
59 if (j
>= sizeof(dev
->name
))
62 if (dev
->name
[j
] == 0 && j
== curr
->name_len
) {
67 if (dev
->name
[j
] == 0 || j
>= curr
->name_len
)
70 if (dev
->name
[j
] != curr
->name
[j
])
76 spin_unlock_irqrestore(&cor_interface_config_lock
, iflags
);
81 void cor_set_interface_config(struct cor_interface_config
*new_config
,
82 __u32 new_num_interfaces
, int new_all_interfaces
)
87 spin_lock_irqsave(&cor_interface_config_lock
, iflags
);
89 BUG_ON(cor_num_interfaces
> 65536);
90 for (i
=0;i
<cor_num_interfaces
;i
++) {
91 struct cor_interface_config
*curr
= &(cor_interface_config
[i
]);
93 BUG_ON(curr
->name
== 0);
98 kfree(cor_interface_config
);
99 cor_interface_config
= 0;
100 cor_num_interfaces
= 0;
101 cor_all_interfaces
= 0;
104 cor_interface_config
= new_config
;
105 cor_num_interfaces
= new_num_interfaces
;
106 cor_all_interfaces
= new_all_interfaces
;
108 spin_unlock_irqrestore(&cor_interface_config_lock
, iflags
);
112 void _cor_config_down(void)
116 spin_lock_bh(&cor_local_addr_lock
);
117 if (cor_local_addr
!= 0) {
118 kfree(cor_local_addr
);
121 cor_local_addrlen
= 0;
122 spin_unlock_bh(&cor_local_addr_lock
);
124 cor_reset_neighbors(0);
125 cor_reset_neighbors(0);
126 cor_destroy_queue(0);
128 cor_announce_send_stop(0, 0, ANNOUNCE_TYPE_BROADCAST
);
131 void cor_config_down(void)
133 mutex_lock(&(cor_config_lock
));
135 mutex_unlock(&(cor_config_lock
));
138 int cor_config_up(char *addr2
, __u32 addrlen2
)
142 char *addr2_copy
= kmalloc(addrlen2
, GFP_KERNEL
);
143 if (unlikely(addr2_copy
== 0))
146 memcpy(addr2_copy
, addr2
, addrlen2
);
148 mutex_lock(&(cor_config_lock
));
152 spin_lock_bh(&cor_local_addr_lock
);
154 BUG_ON(cor_local_addr
!= 0);
155 BUG_ON(cor_local_addrlen
!= 0);
157 cor_local_addr
= addr2_copy
;
159 cor_local_addrlen
= addrlen2
;
160 get_random_bytes((char *) &cor_local_addr_sessionid
,
161 sizeof(cor_local_addr_sessionid
));
163 spin_unlock_bh(&cor_local_addr_lock
);
165 if (cor_dev_up() != 0) {
166 spin_lock_bh(&cor_local_addr_lock
);
167 kfree(cor_local_addr
);
169 cor_local_addrlen
= 0;
170 spin_unlock_bh(&cor_local_addr_lock
);
174 mutex_unlock(&(cor_config_lock
));
179 int cor_is_clientmode(void)
182 spin_lock_bh(&cor_local_addr_lock
);
183 rc
= (cor_local_addrlen
== 0 ? 1 : 0);
184 spin_unlock_bh(&cor_local_addr_lock
);