1 // SPDX-License-Identifier: GPL-2.0-or-later << 2 /* 1 /* 3 * SR-IPv6 implementation 2 * SR-IPv6 implementation 4 * 3 * 5 * Author: 4 * Author: 6 * David Lebrun <david.lebrun@uclouvain.be> 5 * David Lebrun <david.lebrun@uclouvain.be> >> 6 * >> 7 * >> 8 * This program is free software; you can redistribute it and/or >> 9 * modify it under the terms of the GNU General Public License >> 10 * as published by the Free Software Foundation; either version >> 11 * 2 of the License, or (at your option) any later version. 7 */ 12 */ 8 13 9 #include <linux/errno.h> 14 #include <linux/errno.h> 10 #include <linux/types.h> 15 #include <linux/types.h> 11 #include <linux/socket.h> 16 #include <linux/socket.h> 12 #include <linux/net.h> 17 #include <linux/net.h> 13 #include <linux/in6.h> 18 #include <linux/in6.h> 14 #include <linux/slab.h> 19 #include <linux/slab.h> 15 #include <linux/rhashtable.h> 20 #include <linux/rhashtable.h> 16 21 17 #include <net/ipv6.h> 22 #include <net/ipv6.h> 18 #include <net/protocol.h> 23 #include <net/protocol.h> 19 24 20 #include <net/seg6.h> 25 #include <net/seg6.h> 21 #include <net/genetlink.h> 26 #include <net/genetlink.h> 22 #include <linux/seg6.h> 27 #include <linux/seg6.h> 23 #include <linux/seg6_genl.h> 28 #include <linux/seg6_genl.h> >> 29 #ifdef CONFIG_IPV6_SEG6_HMAC 24 #include <net/seg6_hmac.h> 30 #include <net/seg6_hmac.h> >> 31 #endif 25 32 26 bool seg6_validate_srh(struct ipv6_sr_hdr *srh !! 33 bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len) 27 { 34 { 28 unsigned int tlv_offset; << 29 int max_last_entry; << 30 int trailing; 35 int trailing; >> 36 unsigned int tlv_offset; 31 37 32 if (srh->type != IPV6_SRCRT_TYPE_4) 38 if (srh->type != IPV6_SRCRT_TYPE_4) 33 return false; 39 return false; 34 40 35 if (((srh->hdrlen + 1) << 3) != len) 41 if (((srh->hdrlen + 1) << 3) != len) 36 return false; 42 return false; 37 43 38 if (!reduced && srh->segments_left > s !! 44 if (srh->segments_left > srh->first_segment) 39 return false; 45 return false; 40 } else { << 41 max_last_entry = (srh->hdrlen << 42 << 43 if (srh->first_segment > max_l << 44 return false; << 45 << 46 if (srh->segments_left > srh-> << 47 return false; << 48 } << 49 46 50 tlv_offset = sizeof(*srh) + ((srh->fir 47 tlv_offset = sizeof(*srh) + ((srh->first_segment + 1) << 4); 51 48 52 trailing = len - tlv_offset; 49 trailing = len - tlv_offset; 53 if (trailing < 0) 50 if (trailing < 0) 54 return false; 51 return false; 55 52 56 while (trailing) { 53 while (trailing) { 57 struct sr6_tlv *tlv; 54 struct sr6_tlv *tlv; 58 unsigned int tlv_len; 55 unsigned int tlv_len; 59 56 60 if (trailing < sizeof(*tlv)) 57 if (trailing < sizeof(*tlv)) 61 return false; 58 return false; 62 59 63 tlv = (struct sr6_tlv *)((unsi 60 tlv = (struct sr6_tlv *)((unsigned char *)srh + tlv_offset); 64 tlv_len = sizeof(*tlv) + tlv-> 61 tlv_len = sizeof(*tlv) + tlv->len; 65 62 66 trailing -= tlv_len; 63 trailing -= tlv_len; 67 if (trailing < 0) 64 if (trailing < 0) 68 return false; 65 return false; 69 66 70 tlv_offset += tlv_len; 67 tlv_offset += tlv_len; 71 } 68 } 72 69 73 return true; 70 return true; 74 } 71 } 75 72 76 struct ipv6_sr_hdr *seg6_get_srh(struct sk_buf << 77 { << 78 struct ipv6_sr_hdr *srh; << 79 int len, srhoff = 0; << 80 << 81 if (ipv6_find_hdr(skb, &srhoff, IPPROT << 82 return NULL; << 83 << 84 if (!pskb_may_pull(skb, srhoff + sizeo << 85 return NULL; << 86 << 87 srh = (struct ipv6_sr_hdr *)(skb->data << 88 << 89 len = (srh->hdrlen + 1) << 3; << 90 << 91 if (!pskb_may_pull(skb, srhoff + len)) << 92 return NULL; << 93 << 94 /* note that pskb_may_pull may change << 95 * for this reason it is necessary to << 96 */ << 97 srh = (struct ipv6_sr_hdr *)(skb->data << 98 << 99 if (!seg6_validate_srh(srh, len, true) << 100 return NULL; << 101 << 102 return srh; << 103 } << 104 << 105 /* Determine if an ICMP invoking packet contai << 106 * header. If it does, extract the offset to << 107 * address, which is in the first segment addr << 108 */ << 109 void seg6_icmp_srh(struct sk_buff *skb, struct << 110 { << 111 __u16 network_header = skb->network_he << 112 struct ipv6_sr_hdr *srh; << 113 << 114 /* Update network header to point to t << 115 * inside the ICMP packet, so we can u << 116 * helper. << 117 */ << 118 skb_reset_network_header(skb); << 119 << 120 srh = seg6_get_srh(skb, 0); << 121 if (!srh) << 122 goto out; << 123 << 124 if (srh->type != IPV6_SRCRT_TYPE_4) << 125 goto out; << 126 << 127 opt->flags |= IP6SKB_SEG6; << 128 opt->srhoff = (unsigned char *)srh - s << 129 << 130 out: << 131 /* Restore the network header back to << 132 skb->network_header = network_header; << 133 } << 134 << 135 static struct genl_family seg6_genl_family; 73 static struct genl_family seg6_genl_family; 136 74 137 static const struct nla_policy seg6_genl_polic 75 static const struct nla_policy seg6_genl_policy[SEG6_ATTR_MAX + 1] = { 138 [SEG6_ATTR_DST] 76 [SEG6_ATTR_DST] = { .type = NLA_BINARY, 139 .len = sizeof(struct in6_addr) 77 .len = sizeof(struct in6_addr) }, 140 [SEG6_ATTR_DSTLEN] 78 [SEG6_ATTR_DSTLEN] = { .type = NLA_S32, }, 141 [SEG6_ATTR_HMACKEYID] = { .t 79 [SEG6_ATTR_HMACKEYID] = { .type = NLA_U32, }, 142 [SEG6_ATTR_SECRET] 80 [SEG6_ATTR_SECRET] = { .type = NLA_BINARY, }, 143 [SEG6_ATTR_SECRETLEN] = { .t 81 [SEG6_ATTR_SECRETLEN] = { .type = NLA_U8, }, 144 [SEG6_ATTR_ALGID] 82 [SEG6_ATTR_ALGID] = { .type = NLA_U8, }, 145 [SEG6_ATTR_HMACINFO] = { .t 83 [SEG6_ATTR_HMACINFO] = { .type = NLA_NESTED, }, 146 }; 84 }; 147 85 148 #ifdef CONFIG_IPV6_SEG6_HMAC 86 #ifdef CONFIG_IPV6_SEG6_HMAC 149 87 150 static int seg6_genl_sethmac(struct sk_buff *s 88 static int seg6_genl_sethmac(struct sk_buff *skb, struct genl_info *info) 151 { 89 { 152 struct net *net = genl_info_net(info); 90 struct net *net = genl_info_net(info); 153 struct seg6_pernet_data *sdata; 91 struct seg6_pernet_data *sdata; 154 struct seg6_hmac_info *hinfo; 92 struct seg6_hmac_info *hinfo; 155 u32 hmackeyid; 93 u32 hmackeyid; 156 char *secret; 94 char *secret; 157 int err = 0; 95 int err = 0; 158 u8 algid; 96 u8 algid; 159 u8 slen; 97 u8 slen; 160 98 161 sdata = seg6_pernet(net); 99 sdata = seg6_pernet(net); 162 100 163 if (!info->attrs[SEG6_ATTR_HMACKEYID] 101 if (!info->attrs[SEG6_ATTR_HMACKEYID] || 164 !info->attrs[SEG6_ATTR_SECRETLEN] 102 !info->attrs[SEG6_ATTR_SECRETLEN] || 165 !info->attrs[SEG6_ATTR_ALGID]) 103 !info->attrs[SEG6_ATTR_ALGID]) 166 return -EINVAL; 104 return -EINVAL; 167 105 168 hmackeyid = nla_get_u32(info->attrs[SE 106 hmackeyid = nla_get_u32(info->attrs[SEG6_ATTR_HMACKEYID]); 169 slen = nla_get_u8(info->attrs[SEG6_ATT 107 slen = nla_get_u8(info->attrs[SEG6_ATTR_SECRETLEN]); 170 algid = nla_get_u8(info->attrs[SEG6_AT 108 algid = nla_get_u8(info->attrs[SEG6_ATTR_ALGID]); 171 109 172 if (hmackeyid == 0) 110 if (hmackeyid == 0) 173 return -EINVAL; 111 return -EINVAL; 174 112 175 if (slen > SEG6_HMAC_SECRET_LEN) 113 if (slen > SEG6_HMAC_SECRET_LEN) 176 return -EINVAL; 114 return -EINVAL; 177 115 178 mutex_lock(&sdata->lock); 116 mutex_lock(&sdata->lock); 179 hinfo = seg6_hmac_info_lookup(net, hma 117 hinfo = seg6_hmac_info_lookup(net, hmackeyid); 180 118 181 if (!slen) { 119 if (!slen) { >> 120 if (!hinfo) >> 121 err = -ENOENT; >> 122 182 err = seg6_hmac_info_del(net, 123 err = seg6_hmac_info_del(net, hmackeyid); 183 124 184 goto out_unlock; 125 goto out_unlock; 185 } 126 } 186 127 187 if (!info->attrs[SEG6_ATTR_SECRET]) { 128 if (!info->attrs[SEG6_ATTR_SECRET]) { 188 err = -EINVAL; 129 err = -EINVAL; 189 goto out_unlock; 130 goto out_unlock; 190 } 131 } 191 132 192 if (slen > nla_len(info->attrs[SEG6_AT << 193 err = -EINVAL; << 194 goto out_unlock; << 195 } << 196 << 197 if (hinfo) { 133 if (hinfo) { 198 err = seg6_hmac_info_del(net, 134 err = seg6_hmac_info_del(net, hmackeyid); 199 if (err) 135 if (err) 200 goto out_unlock; 136 goto out_unlock; 201 } 137 } 202 138 203 secret = (char *)nla_data(info->attrs[ 139 secret = (char *)nla_data(info->attrs[SEG6_ATTR_SECRET]); 204 140 205 hinfo = kzalloc(sizeof(*hinfo), GFP_KE 141 hinfo = kzalloc(sizeof(*hinfo), GFP_KERNEL); 206 if (!hinfo) { 142 if (!hinfo) { 207 err = -ENOMEM; 143 err = -ENOMEM; 208 goto out_unlock; 144 goto out_unlock; 209 } 145 } 210 146 211 memcpy(hinfo->secret, secret, slen); 147 memcpy(hinfo->secret, secret, slen); 212 hinfo->slen = slen; 148 hinfo->slen = slen; 213 hinfo->alg_id = algid; 149 hinfo->alg_id = algid; 214 hinfo->hmackeyid = hmackeyid; 150 hinfo->hmackeyid = hmackeyid; 215 151 216 err = seg6_hmac_info_add(net, hmackeyi 152 err = seg6_hmac_info_add(net, hmackeyid, hinfo); 217 if (err) 153 if (err) 218 kfree(hinfo); 154 kfree(hinfo); 219 155 220 out_unlock: 156 out_unlock: 221 mutex_unlock(&sdata->lock); 157 mutex_unlock(&sdata->lock); 222 return err; 158 return err; 223 } 159 } 224 160 225 #else 161 #else 226 162 227 static int seg6_genl_sethmac(struct sk_buff *s 163 static int seg6_genl_sethmac(struct sk_buff *skb, struct genl_info *info) 228 { 164 { 229 return -ENOTSUPP; 165 return -ENOTSUPP; 230 } 166 } 231 167 232 #endif 168 #endif 233 169 234 static int seg6_genl_set_tunsrc(struct sk_buff 170 static int seg6_genl_set_tunsrc(struct sk_buff *skb, struct genl_info *info) 235 { 171 { 236 struct net *net = genl_info_net(info); 172 struct net *net = genl_info_net(info); 237 struct in6_addr *val, *t_old, *t_new; 173 struct in6_addr *val, *t_old, *t_new; 238 struct seg6_pernet_data *sdata; 174 struct seg6_pernet_data *sdata; 239 175 240 sdata = seg6_pernet(net); 176 sdata = seg6_pernet(net); 241 177 242 if (!info->attrs[SEG6_ATTR_DST]) 178 if (!info->attrs[SEG6_ATTR_DST]) 243 return -EINVAL; 179 return -EINVAL; 244 180 245 val = nla_data(info->attrs[SEG6_ATTR_D 181 val = nla_data(info->attrs[SEG6_ATTR_DST]); 246 t_new = kmemdup(val, sizeof(*val), GFP 182 t_new = kmemdup(val, sizeof(*val), GFP_KERNEL); 247 if (!t_new) 183 if (!t_new) 248 return -ENOMEM; 184 return -ENOMEM; 249 185 250 mutex_lock(&sdata->lock); 186 mutex_lock(&sdata->lock); 251 187 252 t_old = sdata->tun_src; 188 t_old = sdata->tun_src; 253 rcu_assign_pointer(sdata->tun_src, t_n 189 rcu_assign_pointer(sdata->tun_src, t_new); 254 190 255 mutex_unlock(&sdata->lock); 191 mutex_unlock(&sdata->lock); 256 192 257 synchronize_net(); 193 synchronize_net(); 258 kfree(t_old); 194 kfree(t_old); 259 195 260 return 0; 196 return 0; 261 } 197 } 262 198 263 static int seg6_genl_get_tunsrc(struct sk_buff 199 static int seg6_genl_get_tunsrc(struct sk_buff *skb, struct genl_info *info) 264 { 200 { 265 struct net *net = genl_info_net(info); 201 struct net *net = genl_info_net(info); 266 struct in6_addr *tun_src; 202 struct in6_addr *tun_src; 267 struct sk_buff *msg; 203 struct sk_buff *msg; 268 void *hdr; 204 void *hdr; 269 205 270 msg = genlmsg_new(NLMSG_DEFAULT_SIZE, 206 msg = genlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 271 if (!msg) 207 if (!msg) 272 return -ENOMEM; 208 return -ENOMEM; 273 209 274 hdr = genlmsg_put(msg, info->snd_porti 210 hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq, 275 &seg6_genl_family, 0 211 &seg6_genl_family, 0, SEG6_CMD_GET_TUNSRC); 276 if (!hdr) 212 if (!hdr) 277 goto free_msg; 213 goto free_msg; 278 214 279 rcu_read_lock(); 215 rcu_read_lock(); 280 tun_src = rcu_dereference(seg6_pernet( 216 tun_src = rcu_dereference(seg6_pernet(net)->tun_src); 281 217 282 if (nla_put(msg, SEG6_ATTR_DST, sizeof 218 if (nla_put(msg, SEG6_ATTR_DST, sizeof(struct in6_addr), tun_src)) 283 goto nla_put_failure; 219 goto nla_put_failure; 284 220 285 rcu_read_unlock(); 221 rcu_read_unlock(); 286 222 287 genlmsg_end(msg, hdr); 223 genlmsg_end(msg, hdr); 288 return genlmsg_reply(msg, info); 224 return genlmsg_reply(msg, info); 289 225 290 nla_put_failure: 226 nla_put_failure: 291 rcu_read_unlock(); 227 rcu_read_unlock(); 292 free_msg: 228 free_msg: 293 nlmsg_free(msg); 229 nlmsg_free(msg); 294 return -ENOMEM; 230 return -ENOMEM; 295 } 231 } 296 232 297 #ifdef CONFIG_IPV6_SEG6_HMAC 233 #ifdef CONFIG_IPV6_SEG6_HMAC 298 234 299 static int __seg6_hmac_fill_info(struct seg6_h 235 static int __seg6_hmac_fill_info(struct seg6_hmac_info *hinfo, 300 struct sk_buf 236 struct sk_buff *msg) 301 { 237 { 302 if (nla_put_u32(msg, SEG6_ATTR_HMACKEY 238 if (nla_put_u32(msg, SEG6_ATTR_HMACKEYID, hinfo->hmackeyid) || 303 nla_put_u8(msg, SEG6_ATTR_SECRETLE 239 nla_put_u8(msg, SEG6_ATTR_SECRETLEN, hinfo->slen) || 304 nla_put(msg, SEG6_ATTR_SECRET, hin 240 nla_put(msg, SEG6_ATTR_SECRET, hinfo->slen, hinfo->secret) || 305 nla_put_u8(msg, SEG6_ATTR_ALGID, h 241 nla_put_u8(msg, SEG6_ATTR_ALGID, hinfo->alg_id)) 306 return -1; 242 return -1; 307 243 308 return 0; 244 return 0; 309 } 245 } 310 246 311 static int __seg6_genl_dumphmac_element(struct 247 static int __seg6_genl_dumphmac_element(struct seg6_hmac_info *hinfo, 312 u32 po 248 u32 portid, u32 seq, u32 flags, 313 struct 249 struct sk_buff *skb, u8 cmd) 314 { 250 { 315 void *hdr; 251 void *hdr; 316 252 317 hdr = genlmsg_put(skb, portid, seq, &s 253 hdr = genlmsg_put(skb, portid, seq, &seg6_genl_family, flags, cmd); 318 if (!hdr) 254 if (!hdr) 319 return -ENOMEM; 255 return -ENOMEM; 320 256 321 if (__seg6_hmac_fill_info(hinfo, skb) 257 if (__seg6_hmac_fill_info(hinfo, skb) < 0) 322 goto nla_put_failure; 258 goto nla_put_failure; 323 259 324 genlmsg_end(skb, hdr); 260 genlmsg_end(skb, hdr); 325 return 0; 261 return 0; 326 262 327 nla_put_failure: 263 nla_put_failure: 328 genlmsg_cancel(skb, hdr); 264 genlmsg_cancel(skb, hdr); 329 return -EMSGSIZE; 265 return -EMSGSIZE; 330 } 266 } 331 267 332 static int seg6_genl_dumphmac_start(struct net 268 static int seg6_genl_dumphmac_start(struct netlink_callback *cb) 333 { 269 { 334 struct net *net = sock_net(cb->skb->sk 270 struct net *net = sock_net(cb->skb->sk); 335 struct seg6_pernet_data *sdata; 271 struct seg6_pernet_data *sdata; 336 struct rhashtable_iter *iter; 272 struct rhashtable_iter *iter; 337 273 338 sdata = seg6_pernet(net); 274 sdata = seg6_pernet(net); 339 iter = (struct rhashtable_iter *)cb->a 275 iter = (struct rhashtable_iter *)cb->args[0]; 340 276 341 if (!iter) { 277 if (!iter) { 342 iter = kmalloc(sizeof(*iter), 278 iter = kmalloc(sizeof(*iter), GFP_KERNEL); 343 if (!iter) 279 if (!iter) 344 return -ENOMEM; 280 return -ENOMEM; 345 281 346 cb->args[0] = (long)iter; 282 cb->args[0] = (long)iter; 347 } 283 } 348 284 349 rhashtable_walk_enter(&sdata->hmac_inf 285 rhashtable_walk_enter(&sdata->hmac_infos, iter); 350 286 351 return 0; 287 return 0; 352 } 288 } 353 289 354 static int seg6_genl_dumphmac_done(struct netl 290 static int seg6_genl_dumphmac_done(struct netlink_callback *cb) 355 { 291 { 356 struct rhashtable_iter *iter = (struct 292 struct rhashtable_iter *iter = (struct rhashtable_iter *)cb->args[0]; 357 293 358 rhashtable_walk_exit(iter); 294 rhashtable_walk_exit(iter); 359 295 360 kfree(iter); 296 kfree(iter); 361 297 362 return 0; 298 return 0; 363 } 299 } 364 300 365 static int seg6_genl_dumphmac(struct sk_buff * 301 static int seg6_genl_dumphmac(struct sk_buff *skb, struct netlink_callback *cb) 366 { 302 { 367 struct rhashtable_iter *iter = (struct 303 struct rhashtable_iter *iter = (struct rhashtable_iter *)cb->args[0]; 368 struct seg6_hmac_info *hinfo; 304 struct seg6_hmac_info *hinfo; 369 int ret; 305 int ret; 370 306 371 rhashtable_walk_start(iter); 307 rhashtable_walk_start(iter); 372 308 373 for (;;) { 309 for (;;) { 374 hinfo = rhashtable_walk_next(i 310 hinfo = rhashtable_walk_next(iter); 375 311 376 if (IS_ERR(hinfo)) { 312 if (IS_ERR(hinfo)) { 377 if (PTR_ERR(hinfo) == 313 if (PTR_ERR(hinfo) == -EAGAIN) 378 continue; 314 continue; 379 ret = PTR_ERR(hinfo); 315 ret = PTR_ERR(hinfo); 380 goto done; 316 goto done; 381 } else if (!hinfo) { 317 } else if (!hinfo) { 382 break; 318 break; 383 } 319 } 384 320 385 ret = __seg6_genl_dumphmac_ele 321 ret = __seg6_genl_dumphmac_element(hinfo, 386 322 NETLINK_CB(cb->skb).portid, 387 323 cb->nlh->nlmsg_seq, 388 324 NLM_F_MULTI, 389 325 skb, SEG6_CMD_DUMPHMAC); 390 if (ret) 326 if (ret) 391 goto done; 327 goto done; 392 } 328 } 393 329 394 ret = skb->len; 330 ret = skb->len; 395 331 396 done: 332 done: 397 rhashtable_walk_stop(iter); 333 rhashtable_walk_stop(iter); 398 return ret; 334 return ret; 399 } 335 } 400 336 401 #else 337 #else 402 338 403 static int seg6_genl_dumphmac_start(struct net 339 static int seg6_genl_dumphmac_start(struct netlink_callback *cb) 404 { 340 { 405 return 0; 341 return 0; 406 } 342 } 407 343 408 static int seg6_genl_dumphmac_done(struct netl 344 static int seg6_genl_dumphmac_done(struct netlink_callback *cb) 409 { 345 { 410 return 0; 346 return 0; 411 } 347 } 412 348 413 static int seg6_genl_dumphmac(struct sk_buff * 349 static int seg6_genl_dumphmac(struct sk_buff *skb, struct netlink_callback *cb) 414 { 350 { 415 return -ENOTSUPP; 351 return -ENOTSUPP; 416 } 352 } 417 353 418 #endif 354 #endif 419 355 420 static int __net_init seg6_net_init(struct net 356 static int __net_init seg6_net_init(struct net *net) 421 { 357 { 422 struct seg6_pernet_data *sdata; 358 struct seg6_pernet_data *sdata; 423 359 424 sdata = kzalloc(sizeof(*sdata), GFP_KE 360 sdata = kzalloc(sizeof(*sdata), GFP_KERNEL); 425 if (!sdata) 361 if (!sdata) 426 return -ENOMEM; 362 return -ENOMEM; 427 363 428 mutex_init(&sdata->lock); 364 mutex_init(&sdata->lock); 429 365 430 sdata->tun_src = kzalloc(sizeof(*sdata 366 sdata->tun_src = kzalloc(sizeof(*sdata->tun_src), GFP_KERNEL); 431 if (!sdata->tun_src) { 367 if (!sdata->tun_src) { 432 kfree(sdata); 368 kfree(sdata); 433 return -ENOMEM; 369 return -ENOMEM; 434 } 370 } 435 371 436 net->ipv6.seg6_data = sdata; 372 net->ipv6.seg6_data = sdata; 437 373 438 if (seg6_hmac_net_init(net)) { !! 374 #ifdef CONFIG_IPV6_SEG6_HMAC 439 kfree(rcu_dereference_raw(sdat !! 375 seg6_hmac_net_init(net); 440 kfree(sdata); !! 376 #endif 441 return -ENOMEM; << 442 } << 443 377 444 return 0; 378 return 0; 445 } 379 } 446 380 447 static void __net_exit seg6_net_exit(struct ne 381 static void __net_exit seg6_net_exit(struct net *net) 448 { 382 { 449 struct seg6_pernet_data *sdata = seg6_ 383 struct seg6_pernet_data *sdata = seg6_pernet(net); 450 384 >> 385 #ifdef CONFIG_IPV6_SEG6_HMAC 451 seg6_hmac_net_exit(net); 386 seg6_hmac_net_exit(net); >> 387 #endif 452 388 453 kfree(rcu_dereference_raw(sdata->tun_s !! 389 kfree(sdata->tun_src); 454 kfree(sdata); 390 kfree(sdata); 455 } 391 } 456 392 457 static struct pernet_operations ip6_segments_o 393 static struct pernet_operations ip6_segments_ops = { 458 .init = seg6_net_init, 394 .init = seg6_net_init, 459 .exit = seg6_net_exit, 395 .exit = seg6_net_exit, 460 }; 396 }; 461 397 462 static const struct genl_ops seg6_genl_ops[] = 398 static const struct genl_ops seg6_genl_ops[] = { 463 { 399 { 464 .cmd = SEG6_CMD_SETHMAC, 400 .cmd = SEG6_CMD_SETHMAC, 465 .validate = GENL_DONT_VALIDATE << 466 .doit = seg6_genl_sethmac, 401 .doit = seg6_genl_sethmac, >> 402 .policy = seg6_genl_policy, 467 .flags = GENL_ADMIN_PERM, 403 .flags = GENL_ADMIN_PERM, 468 }, 404 }, 469 { 405 { 470 .cmd = SEG6_CMD_DUMPHMAC, 406 .cmd = SEG6_CMD_DUMPHMAC, 471 .validate = GENL_DONT_VALIDATE << 472 .start = seg6_genl_dumphmac_s 407 .start = seg6_genl_dumphmac_start, 473 .dumpit = seg6_genl_dumphmac, 408 .dumpit = seg6_genl_dumphmac, 474 .done = seg6_genl_dumphmac_d 409 .done = seg6_genl_dumphmac_done, >> 410 .policy = seg6_genl_policy, 475 .flags = GENL_ADMIN_PERM, 411 .flags = GENL_ADMIN_PERM, 476 }, 412 }, 477 { 413 { 478 .cmd = SEG6_CMD_SET_TUNSRC, 414 .cmd = SEG6_CMD_SET_TUNSRC, 479 .validate = GENL_DONT_VALIDATE << 480 .doit = seg6_genl_set_tunsrc 415 .doit = seg6_genl_set_tunsrc, >> 416 .policy = seg6_genl_policy, 481 .flags = GENL_ADMIN_PERM, 417 .flags = GENL_ADMIN_PERM, 482 }, 418 }, 483 { 419 { 484 .cmd = SEG6_CMD_GET_TUNSRC, 420 .cmd = SEG6_CMD_GET_TUNSRC, 485 .validate = GENL_DONT_VALIDATE << 486 .doit = seg6_genl_get_tunsrc 421 .doit = seg6_genl_get_tunsrc, >> 422 .policy = seg6_genl_policy, 487 .flags = GENL_ADMIN_PERM, 423 .flags = GENL_ADMIN_PERM, 488 }, 424 }, 489 }; 425 }; 490 426 491 static struct genl_family seg6_genl_family __r 427 static struct genl_family seg6_genl_family __ro_after_init = { 492 .hdrsize = 0, 428 .hdrsize = 0, 493 .name = SEG6_GENL_NAME, 429 .name = SEG6_GENL_NAME, 494 .version = SEG6_GENL_VERSION, 430 .version = SEG6_GENL_VERSION, 495 .maxattr = SEG6_ATTR_MAX, 431 .maxattr = SEG6_ATTR_MAX, 496 .policy = seg6_genl_policy, << 497 .netnsok = true, 432 .netnsok = true, 498 .parallel_ops = true, 433 .parallel_ops = true, 499 .ops = seg6_genl_ops, 434 .ops = seg6_genl_ops, 500 .n_ops = ARRAY_SIZE(seg6_genl 435 .n_ops = ARRAY_SIZE(seg6_genl_ops), 501 .resv_start_op = SEG6_CMD_GET_TUNSRC << 502 .module = THIS_MODULE, 436 .module = THIS_MODULE, 503 }; 437 }; 504 438 505 int __init seg6_init(void) 439 int __init seg6_init(void) 506 { 440 { 507 int err; !! 441 int err = -ENOMEM; 508 442 509 err = register_pernet_subsys(&ip6_segm !! 443 err = genl_register_family(&seg6_genl_family); 510 if (err) 444 if (err) 511 goto out; 445 goto out; 512 446 513 err = genl_register_family(&seg6_genl_ !! 447 err = register_pernet_subsys(&ip6_segments_ops); 514 if (err) 448 if (err) 515 goto out_unregister_pernet; !! 449 goto out_unregister_genl; 516 450 >> 451 #ifdef CONFIG_IPV6_SEG6_LWTUNNEL 517 err = seg6_iptunnel_init(); 452 err = seg6_iptunnel_init(); 518 if (err) 453 if (err) 519 goto out_unregister_genl; !! 454 goto out_unregister_pernet; 520 455 521 err = seg6_local_init(); 456 err = seg6_local_init(); 522 if (err) 457 if (err) 523 goto out_unregister_iptun; !! 458 goto out_unregister_pernet; >> 459 #endif 524 460 >> 461 #ifdef CONFIG_IPV6_SEG6_HMAC 525 err = seg6_hmac_init(); 462 err = seg6_hmac_init(); 526 if (err) 463 if (err) 527 goto out_unregister_seg6; !! 464 goto out_unregister_iptun; >> 465 #endif 528 466 529 pr_info("Segment Routing with IPv6\n") 467 pr_info("Segment Routing with IPv6\n"); 530 468 531 out: 469 out: 532 return err; 470 return err; 533 out_unregister_seg6: !! 471 #ifdef CONFIG_IPV6_SEG6_HMAC 534 seg6_local_exit(); << 535 out_unregister_iptun: 472 out_unregister_iptun: >> 473 #ifdef CONFIG_IPV6_SEG6_LWTUNNEL >> 474 seg6_local_exit(); 536 seg6_iptunnel_exit(); 475 seg6_iptunnel_exit(); 537 out_unregister_genl: !! 476 #endif 538 genl_unregister_family(&seg6_genl_fami !! 477 #endif >> 478 #ifdef CONFIG_IPV6_SEG6_LWTUNNEL 539 out_unregister_pernet: 479 out_unregister_pernet: 540 unregister_pernet_subsys(&ip6_segments 480 unregister_pernet_subsys(&ip6_segments_ops); >> 481 #endif >> 482 out_unregister_genl: >> 483 genl_unregister_family(&seg6_genl_family); 541 goto out; 484 goto out; 542 } 485 } 543 486 544 void seg6_exit(void) 487 void seg6_exit(void) 545 { 488 { >> 489 #ifdef CONFIG_IPV6_SEG6_HMAC 546 seg6_hmac_exit(); 490 seg6_hmac_exit(); 547 seg6_local_exit(); !! 491 #endif >> 492 #ifdef CONFIG_IPV6_SEG6_LWTUNNEL 548 seg6_iptunnel_exit(); 493 seg6_iptunnel_exit(); 549 genl_unregister_family(&seg6_genl_fami !! 494 #endif 550 unregister_pernet_subsys(&ip6_segments 495 unregister_pernet_subsys(&ip6_segments_ops); >> 496 genl_unregister_family(&seg6_genl_family); 551 } 497 } 552 498
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.