* The protocol to be inserted into ip6_protox[] must be already registered * in inet6sw[], either statically or through pf_proto_register(). */
| 293 | * in inet6sw[], either statically or through pf_proto_register(). |
| 294 | */ |
| 295 | int |
| 296 | ip6proto_register(short ip6proto) |
| 297 | { |
| 298 | struct protosw *pr; |
| 299 | |
| 300 | /* Sanity checks. */ |
| 301 | if (ip6proto <= 0 || ip6proto >= IPPROTO_MAX) |
| 302 | return (EPROTONOSUPPORT); |
| 303 | |
| 304 | /* |
| 305 | * The protocol slot must not be occupied by another protocol |
| 306 | * already. An index pointing to IPPROTO_RAW is unused. |
| 307 | */ |
| 308 | pr = pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW); |
| 309 | if (pr == NULL) |
| 310 | return (EPFNOSUPPORT); |
| 311 | if (ip6_protox[ip6proto] != pr - inet6sw) /* IPPROTO_RAW */ |
| 312 | return (EEXIST); |
| 313 | |
| 314 | /* |
| 315 | * Find the protocol position in inet6sw[] and set the index. |
| 316 | */ |
| 317 | for (pr = inet6domain.dom_protosw; |
| 318 | pr < inet6domain.dom_protoswNPROTOSW; pr++) { |
| 319 | if (pr->pr_domain->dom_family == PF_INET6 && |
| 320 | pr->pr_protocol && pr->pr_protocol == ip6proto) { |
| 321 | ip6_protox[pr->pr_protocol] = pr - inet6sw; |
| 322 | return (0); |
| 323 | } |
| 324 | } |
| 325 | return (EPROTONOSUPPORT); |
| 326 | } |
| 327 | |
| 328 | int |
| 329 | ip6proto_unregister(short ip6proto) |
no test coverage detected