| 33 | #include "ff_ipc.h" |
| 34 | |
| 35 | static int |
| 36 | ipfw_ctl(int cmd, int level, int optname, void *optval, socklen_t *optlen) |
| 37 | { |
| 38 | struct ff_msg *msg, *retmsg = NULL; |
| 39 | int len; |
| 40 | |
| 41 | switch (cmd) { |
| 42 | case FF_IPFW_GET: |
| 43 | if (optval == NULL || optlen == NULL) { |
| 44 | return EINVAL; |
| 45 | } |
| 46 | break; |
| 47 | case FF_IPFW_SET: |
| 48 | break; |
| 49 | default: |
| 50 | return EINVAL; |
| 51 | } |
| 52 | |
| 53 | msg = ff_ipc_msg_alloc(); |
| 54 | if (msg == NULL) { |
| 55 | errno = ENOMEM; |
| 56 | return -1; |
| 57 | } |
| 58 | |
| 59 | len = sizeof(struct ff_ipfw_args) + *optlen + sizeof(socklen_t); |
| 60 | if (len > msg->buf_len) { |
| 61 | errno = EINVAL; |
| 62 | ff_ipc_msg_free(msg); |
| 63 | return -1; |
| 64 | } |
| 65 | |
| 66 | msg->msg_type = FF_IPFW_CTL; |
| 67 | msg->ipfw.cmd = cmd; |
| 68 | msg->ipfw.level = level; |
| 69 | msg->ipfw.optname = optname; |
| 70 | msg->ipfw.optval = (void *)msg->buf_addr; |
| 71 | msg->ipfw.optlen = (socklen_t *)(msg->buf_addr + (*optlen)); |
| 72 | |
| 73 | memcpy(msg->ipfw.optval, optval, *optlen); |
| 74 | memcpy(msg->ipfw.optlen, optlen, sizeof(socklen_t)); |
| 75 | |
| 76 | int ret = ff_ipc_send(msg); |
| 77 | if (ret < 0) { |
| 78 | errno = EPIPE; |
| 79 | ff_ipc_msg_free(msg); |
| 80 | return -1; |
| 81 | } |
| 82 | |
| 83 | do { |
| 84 | if (retmsg != NULL) { |
| 85 | ff_ipc_msg_free(retmsg); |
| 86 | } |
| 87 | ret = ff_ipc_recv(&retmsg, msg->msg_type); |
| 88 | if (ret < 0) { |
| 89 | errno = EPIPE; |
| 90 | return -1; |
| 91 | } |
| 92 | } while (msg != retmsg); |
no test coverage detected