Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/uipc_socket.c
| Show First 20 Lines • Show All 3,804 Lines • ▼ Show 20 Lines | |||||
| /* | /* | ||||
| * Perhaps this routine, and sooptcopyout(), below, ought to come in an | * Perhaps this routine, and sooptcopyout(), below, ought to come in an | ||||
| * additional variant to handle the case where the option value needs to be | * additional variant to handle the case where the option value needs to be | ||||
| * some kind of integer, but not a specific size. In addition to their use | * some kind of integer, but not a specific size. In addition to their use | ||||
| * here, these functions are also called by the protocol-level pr_ctloutput() | * here, these functions are also called by the protocol-level pr_ctloutput() | ||||
| * routines. | * routines. | ||||
| */ | */ | ||||
| int | static int | ||||
| sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen) | _sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen, | ||||
| bool copycaps) | |||||
| { | { | ||||
| size_t valsize; | size_t valsize; | ||||
| /* | /* | ||||
| * If the user gives us more than we wanted, we ignore it, but if we | * If the user gives us more than we wanted, we ignore it, but if we | ||||
| * don't get the minimum length the caller wants, we return EINVAL. | * don't get the minimum length the caller wants, we return EINVAL. | ||||
| * On success, sopt->sopt_valsize is set to however much we actually | * On success, sopt->sopt_valsize is set to however much we actually | ||||
| * retrieved. | * retrieved. | ||||
| */ | */ | ||||
| if ((valsize = sopt->sopt_valsize) < minlen) | if ((valsize = sopt->sopt_valsize) < minlen) | ||||
| return EINVAL; | return EINVAL; | ||||
| if (valsize > len) | if (valsize > len) | ||||
| sopt->sopt_valsize = valsize = len; | sopt->sopt_valsize = valsize = len; | ||||
| if (sopt->sopt_td != NULL) | if (sopt->sopt_td != NULL) { | ||||
| if (copycaps) | |||||
| return (copyinptr(sopt->sopt_val, buf, valsize)); | |||||
| else | |||||
| return (copyin(sopt->sopt_val, buf, valsize)); | return (copyin(sopt->sopt_val, buf, valsize)); | ||||
| } | |||||
| bcopy(sopt->sopt_val, buf, valsize); | if (copycaps) | ||||
| memcpy(buf, sopt->sopt_val, valsize); | |||||
| else | |||||
| memcpy_data(buf, sopt->sopt_val, valsize); | |||||
| return (0); | return (0); | ||||
| } | |||||
| int | |||||
| sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen) | |||||
| { | |||||
| return (_sooptcopyin(sopt, buf, len, minlen, false)); | |||||
| } | |||||
| #ifdef __CHERI__ | |||||
| int | |||||
| sooptcopyinptr(struct sockopt *sopt, void *buf, size_t len, size_t minlen) | |||||
| { | |||||
| return (_sooptcopyin(sopt, buf, len, minlen, true)); | |||||
| } | } | ||||
| #endif | |||||
| /* | /* | ||||
| * Kernel version of setsockopt(2). | * Kernel version of setsockopt(2). | ||||
| * | * | ||||
| * XXX: optlen is size_t, not socklen_t | * XXX: optlen is size_t, not socklen_t | ||||
| */ | */ | ||||
| int | int | ||||
| so_setsockopt(struct socket *so, int level, int optname, void *optval, | so_setsockopt(struct socket *so, int level, int optname, void *optval, | ||||
| ▲ Show 20 Lines • Show All 263 Lines • ▼ Show 20 Lines | sooptcopyout(struct sockopt *sopt, const void *buf, size_t len) | ||||
| * answer must be generated ahead of time. | * answer must be generated ahead of time. | ||||
| */ | */ | ||||
| valsize = min(len, sopt->sopt_valsize); | valsize = min(len, sopt->sopt_valsize); | ||||
| sopt->sopt_valsize = valsize; | sopt->sopt_valsize = valsize; | ||||
| if (sopt->sopt_val != NULL) { | if (sopt->sopt_val != NULL) { | ||||
| if (sopt->sopt_td != NULL) | if (sopt->sopt_td != NULL) | ||||
| error = copyout(buf, sopt->sopt_val, valsize); | error = copyout(buf, sopt->sopt_val, valsize); | ||||
| else | else | ||||
| bcopy(buf, sopt->sopt_val, valsize); | memcpy_data(sopt->sopt_val, buf, valsize); | ||||
| } | } | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| int | int | ||||
| sogetopt(struct socket *so, struct sockopt *sopt) | sogetopt(struct socket *so, struct sockopt *sopt) | ||||
| { | { | ||||
| int error, optval; | int error, optval; | ||||
| ▲ Show 20 Lines • Show All 1,028 Lines • Show Last 20 Lines | |||||