| 918 | */ |
| 919 | #define IPSEC_REQID_TRYCNT 64 |
| 920 | static int |
| 921 | ipsec_init_reqid(struct ipsec_softc *sc) |
| 922 | { |
| 923 | uint32_t reqid; |
| 924 | int trycount; |
| 925 | |
| 926 | sx_assert(&ipsec_ioctl_sx, SA_XLOCKED); |
| 927 | if (sc->reqid != 0) /* already initialized */ |
| 928 | return (0); |
| 929 | |
| 930 | trycount = IPSEC_REQID_TRYCNT; |
| 931 | while (--trycount > 0) { |
| 932 | reqid = key_newreqid(); |
| 933 | if (ipsec_check_reqid(reqid) == 0) |
| 934 | break; |
| 935 | } |
| 936 | if (trycount == 0) |
| 937 | return (EEXIST); |
| 938 | sc->reqid = reqid; |
| 939 | CK_LIST_INSERT_HEAD(ipsec_idhash(reqid), sc, idhash); |
| 940 | return (0); |
| 941 | } |
| 942 | |
| 943 | /* |
| 944 | * Set or update reqid for given tunneling interface. |
no test coverage detected