* The protocol to be inserted into ip_protox[] must be already registered * in inetsw[], either statically or through pf_proto_register(). */
| 870 | * in inetsw[], either statically or through pf_proto_register(). |
| 871 | */ |
| 872 | int |
| 873 | ipproto_register(short ipproto) |
| 874 | { |
| 875 | struct protosw *pr; |
| 876 | |
| 877 | /* Sanity checks. */ |
| 878 | if (ipproto <= 0 || ipproto >= IPPROTO_MAX) |
| 879 | return (EPROTONOSUPPORT); |
| 880 | |
| 881 | /* |
| 882 | * The protocol slot must not be occupied by another protocol |
| 883 | * already. An index pointing to IPPROTO_RAW is unused. |
| 884 | */ |
| 885 | pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW); |
| 886 | if (pr == NULL) |
| 887 | return (EPFNOSUPPORT); |
| 888 | if (ip_protox[ipproto] != pr - inetsw) /* IPPROTO_RAW */ |
| 889 | return (EEXIST); |
| 890 | |
| 891 | /* Find the protocol position in inetsw[] and set the index. */ |
| 892 | for (pr = inetdomain.dom_protosw; |
| 893 | pr < inetdomain.dom_protoswNPROTOSW; pr++) { |
| 894 | if (pr->pr_domain->dom_family == PF_INET && |
| 895 | pr->pr_protocol && pr->pr_protocol == ipproto) { |
| 896 | ip_protox[pr->pr_protocol] = pr - inetsw; |
| 897 | return (0); |
| 898 | } |
| 899 | } |
| 900 | return (EPROTONOSUPPORT); |
| 901 | } |
| 902 | |
| 903 | int |
| 904 | ipproto_unregister(short ipproto) |
no test coverage detected