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.
18 static DEFINE_MUTEX(cor_config_lock
);
20 DEFINE_SPINLOCK(cor_local_addr_lock
);
21 __u8 cor_local_has_addr
;
22 __be64 cor_local_addr
;
23 __be32 cor_local_addr_sessionid
;
26 static DEFINE_SPINLOCK(cor_interface_config_lock
);
27 static struct cor_interface_config
*cor_interface_config
;
28 static __u32 cor_num_interfaces
;
29 static int cor_all_interfaces
;
32 int cor_is_device_configurated(struct net_device
*dev
)
40 spin_lock_irqsave(&cor_interface_config_lock
, iflags
);
42 if (cor_all_interfaces
!= 0) {
47 BUG_ON(cor_num_interfaces
> 65536);
48 for (i
= 0; i
< cor_num_interfaces
; i
++) {
49 struct cor_interface_config
*curr
= &cor_interface_config
[i
];
52 BUG_ON(curr
->name
== 0);
55 if (j
>= sizeof(dev
->name
))
58 if (dev
->name
[j
] == 0 && j
== curr
->name_len
) {
63 if (dev
->name
[j
] == 0 || j
>= curr
->name_len
)
66 if (dev
->name
[j
] != curr
->name
[j
])
72 spin_unlock_irqrestore(&cor_interface_config_lock
, iflags
);
77 void cor_set_interface_config(struct cor_interface_config
*new_config
,
78 __u32 new_num_interfaces
, int new_all_interfaces
)
83 spin_lock_irqsave(&cor_interface_config_lock
, iflags
);
85 BUG_ON(cor_num_interfaces
> 65536);
86 for (i
= 0; i
< cor_num_interfaces
; i
++) {
87 struct cor_interface_config
*curr
= &cor_interface_config
[i
];
89 BUG_ON(curr
->name
== 0);
94 kfree(cor_interface_config
);
95 cor_interface_config
= 0;
96 cor_num_interfaces
= 0;
97 cor_all_interfaces
= 0;
100 cor_interface_config
= new_config
;
101 cor_num_interfaces
= new_num_interfaces
;
102 cor_all_interfaces
= new_all_interfaces
;
104 spin_unlock_irqrestore(&cor_interface_config_lock
, iflags
);
108 void _cor_config_down(void)
112 spin_lock_bh(&cor_local_addr_lock
);
113 cor_local_has_addr
= 0;
115 spin_unlock_bh(&cor_local_addr_lock
);
117 cor_reset_neighbors(0);
118 cor_reset_neighbors(0);
121 cor_announce_send_stop(0, 0, ANNOUNCE_TYPE_BROADCAST
);
124 void cor_config_down(void)
126 mutex_lock(&cor_config_lock
);
128 mutex_unlock(&cor_config_lock
);
131 int cor_config_up(__u8 has_addr
, __be64 addr
)
135 if (has_addr
!= 0 && be64_to_cpu(addr
) == 0)
138 mutex_lock(&cor_config_lock
);
142 spin_lock_bh(&cor_local_addr_lock
);
144 BUG_ON(cor_local_has_addr
!= 0);
145 BUG_ON(cor_local_addr
!= 0);
147 cor_local_has_addr
= has_addr
;
148 cor_local_addr
= addr
;
149 get_random_bytes((char *) &cor_local_addr_sessionid
,
150 sizeof(cor_local_addr_sessionid
));
152 spin_unlock_bh(&cor_local_addr_lock
);
154 if (cor_dev_up() != 0) {
155 spin_lock_bh(&cor_local_addr_lock
);
156 cor_local_has_addr
= 0;
158 spin_unlock_bh(&cor_local_addr_lock
);
162 mutex_unlock(&cor_config_lock
);
167 int cor_is_clientmode(void)
171 spin_lock_bh(&cor_local_addr_lock
);
172 rc
= (cor_local_has_addr
== 0);
173 spin_unlock_bh(&cor_local_addr_lock
);
177 MODULE_LICENSE("GPL");