Lines Matching refs:ss
130 typedef void snl_parse_field_f(struct snl_state *ss, void *hdr, void *target);
137 typedef bool snl_parse_attr_f(struct snl_state *ss, struct nlattr *attr,
151 typedef bool snl_parse_post_f(struct snl_state *ss, void *target);
202 snl_allocz(struct snl_state *ss, int len) in snl_allocz() argument
204 void *data = lb_allocz(ss->lb, len); in snl_allocz()
207 uint32_t size = ss->lb->size * 2; in snl_allocz()
215 lb->next = ss->lb; in snl_allocz()
216 ss->lb = lb; in snl_allocz()
217 data = lb_allocz(ss->lb, len); in snl_allocz()
225 snl_clear_lb(struct snl_state *ss) in snl_clear_lb() argument
227 struct linear_buffer *lb = ss->lb; in snl_clear_lb()
231 ss->lb->next = NULL; in snl_clear_lb()
241 snl_free(struct snl_state *ss) in snl_free() argument
243 if (ss->init_done) { in snl_free()
244 close(ss->fd); in snl_free()
245 if (ss->buf != NULL) in snl_free()
246 free(ss->buf); in snl_free()
247 if (ss->lb != NULL) { in snl_free()
248 snl_clear_lb(ss); in snl_free()
249 lb_free(ss->lb); in snl_free()
255 snl_init(struct snl_state *ss, int netlink_family) in snl_init() argument
257 memset(ss, 0, sizeof(*ss)); in snl_init()
259 ss->fd = socket(AF_NETLINK, SOCK_RAW, netlink_family); in snl_init()
260 if (ss->fd == -1) in snl_init()
262 ss->init_done = true; in snl_init()
266 if (setsockopt(ss->fd, SOL_NETLINK, NETLINK_EXT_ACK, &val, optlen) == -1) { in snl_init()
267 snl_free(ss); in snl_init()
272 if (getsockopt(ss->fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, &optlen) == -1) { in snl_init()
273 snl_free(ss); in snl_init()
277 ss->bufsize = rcvbuf; in snl_init()
278 ss->buf = (char *)malloc(ss->bufsize); in snl_init()
279 if (ss->buf == NULL) { in snl_init()
280 snl_free(ss); in snl_init()
284 ss->lb = lb_init(SCRATCH_BUFFER_SIZE); in snl_init()
285 if (ss->lb == NULL) { in snl_init()
286 snl_free(ss); in snl_init()
294 snl_send(struct snl_state *ss, void *data, int sz) in snl_send() argument
296 return (send(ss->fd, data, sz, 0) == sz); in snl_send()
300 snl_send_message(struct snl_state *ss, struct nlmsghdr *hdr) in snl_send_message() argument
304 return (send(ss->fd, hdr, sz, 0) == sz); in snl_send_message()
308 snl_get_seq(struct snl_state *ss) in snl_get_seq() argument
310 return (++ss->seq); in snl_get_seq()
320 static inline bool parse_cmsg(struct snl_state *ss, const struct msghdr *msg,
324 snl_read_message_dbg(struct snl_state *ss, struct snl_msg_info *cinfo) in snl_read_message_dbg() argument
328 if (ss->off == ss->datalen) { in snl_read_message_dbg()
333 .iov_base = ss->buf, in snl_read_message_dbg()
334 .iov_len = ss->bufsize, in snl_read_message_dbg()
344 ss->off = 0; in snl_read_message_dbg()
345 ss->datalen = 0; in snl_read_message_dbg()
347 ssize_t datalen = recvmsg(ss->fd, &msg, 0); in snl_read_message_dbg()
349 ss->datalen = datalen; in snl_read_message_dbg()
350 parse_cmsg(ss, &msg, cinfo); in snl_read_message_dbg()
356 struct nlmsghdr *hdr = (struct nlmsghdr *)(void *)&ss->buf[ss->off]; in snl_read_message_dbg()
357 ss->off += NLMSG_ALIGN(hdr->nlmsg_len); in snl_read_message_dbg()
363 snl_read_message(struct snl_state *ss) in snl_read_message() argument
365 if (ss->off == ss->datalen) { in snl_read_message()
368 .iov_base = ss->buf, in snl_read_message()
369 .iov_len = ss->bufsize, in snl_read_message()
377 ss->off = 0; in snl_read_message()
378 ss->datalen = 0; in snl_read_message()
380 ssize_t datalen = recvmsg(ss->fd, &msg, 0); in snl_read_message()
382 ss->datalen = datalen; in snl_read_message()
388 struct nlmsghdr *hdr = (struct nlmsghdr *)(void *)&ss->buf[ss->off]; in snl_read_message()
389 ss->off += NLMSG_ALIGN(hdr->nlmsg_len); in snl_read_message()
394 snl_read_reply(struct snl_state *ss, uint32_t nlmsg_seq) in snl_read_reply() argument
398 while ((hdr = snl_read_message(ss)) != NULL) { in snl_read_reply()
448 snl_parse_attrs_raw(struct snl_state *ss, struct nlattr *nla_head, int len, in snl_parse_attrs_raw() argument
460 if (!s->cb(ss, nla, s->arg, ptr)) in snl_parse_attrs_raw()
468 snl_parse_attrs(struct snl_state *ss, struct nlmsghdr *hdr, int hdrlen, in snl_parse_attrs() argument
475 return (snl_parse_attrs_raw(ss, nla_head, len, ps, pslen, target)); in snl_parse_attrs()
479 snl_parse_fields(struct snl_state *ss, struct nlmsghdr *hdr, int hdrlen __unused, in snl_parse_fields() argument
487 fp->cb(ss, src, dst); in snl_parse_fields()
492 snl_parse_header(struct snl_state *ss, void *hdr, int len, in snl_parse_header() argument
498 snl_parse_fields(ss, (struct nlmsghdr *)hdr, parser->in_hdr_size, in snl_parse_header()
502 bool result = snl_parse_attrs_raw(ss, nla_head, len - parser->in_hdr_size, in snl_parse_header()
506 result = parser->cb_post(ss, target); in snl_parse_header()
512 snl_parse_nlmsg(struct snl_state *ss, struct nlmsghdr *hdr, in snl_parse_nlmsg() argument
515 return (snl_parse_header(ss, hdr + 1, hdr->nlmsg_len - sizeof(*hdr), parser, target)); in snl_parse_nlmsg()
519 snl_attr_get_flag(struct snl_state *ss __unused, struct nlattr *nla, const void *arg __unused, in snl_attr_get_flag()
530 snl_attr_get_bytes(struct snl_state *ss __unused, struct nlattr *nla, const void *arg, in snl_attr_get_bytes()
542 snl_attr_get_bool(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_bool()
553 snl_attr_get_uint8(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_uint8()
564 snl_attr_get_uint16(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_uint16()
575 snl_attr_get_uint32(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_uint32()
586 snl_attr_get_uint64(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_uint64()
597 snl_attr_get_int8(struct snl_state *ss, struct nlattr *nla, const void *arg, in snl_attr_get_int8() argument
600 return (snl_attr_get_uint8(ss, nla, arg, target)); in snl_attr_get_int8()
604 snl_attr_get_int16(struct snl_state *ss, struct nlattr *nla, const void *arg, in snl_attr_get_int16() argument
607 return (snl_attr_get_uint16(ss, nla, arg, target)); in snl_attr_get_int16()
611 snl_attr_get_int32(struct snl_state *ss, struct nlattr *nla, const void *arg, in snl_attr_get_int32() argument
614 return (snl_attr_get_uint32(ss, nla, arg, target)); in snl_attr_get_int32()
618 snl_attr_get_int64(struct snl_state *ss, struct nlattr *nla, const void *arg, in snl_attr_get_int64() argument
621 return (snl_attr_get_uint64(ss, nla, arg, target)); in snl_attr_get_int64()
625 snl_attr_get_string(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_string()
638 snl_attr_get_stringn(struct snl_state *ss, struct nlattr *nla, in snl_attr_get_stringn() argument
643 char *buf = (char *)snl_allocz(ss, maxlen + 1); in snl_attr_get_stringn()
654 snl_attr_copy_string(struct snl_state *ss, struct nlattr *nla, in snl_attr_copy_string() argument
659 if (snl_attr_get_string(ss, nla, NULL, &tmp)) { in snl_attr_copy_string()
667 snl_attr_dup_string(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_dup_string()
673 char *buf = (char *)snl_allocz(ss, maxlen); in snl_attr_dup_string()
684 snl_attr_get_nested(struct snl_state *ss, struct nlattr *nla, const void *arg, void *target) in snl_attr_get_nested() argument
689 return (snl_parse_header(ss, NLA_DATA(nla), NLA_DATA_LEN(nla), p, target)); in snl_attr_get_nested()
698 snl_attr_get_parray_sz(struct snl_state *ss, struct nlattr *container_nla, in snl_attr_get_parray_sz() argument
709 array->items = (void **)snl_allocz(ss, size * sizeof(void *)); in snl_attr_get_parray_sz()
726 void *item = snl_allocz(ss, p->out_size); in snl_attr_get_parray_sz()
734 if (!(snl_parse_header(ss, data, data_len, p, item))) in snl_attr_get_parray_sz()
739 void **new_array = (void **)snl_allocz(ss, new_size *sizeof(void *)); in snl_attr_get_parray_sz()
759 snl_attr_get_parray(struct snl_state *ss, struct nlattr *nla, const void *arg, void *target) in snl_attr_get_parray() argument
761 return (snl_attr_get_parray_sz(ss, nla, 8, arg, target)); in snl_attr_get_parray()
765 snl_attr_get_nla(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_nla()
773 snl_attr_dup_nla(struct snl_state *ss, struct nlattr *nla, in snl_attr_dup_nla() argument
776 void *ptr = snl_allocz(ss, nla->nla_len); in snl_attr_dup_nla()
787 snl_attr_copy_struct(struct snl_state *ss, struct nlattr *nla, in snl_attr_copy_struct() argument
790 void *ptr = snl_allocz(ss, NLA_DATA_LEN(nla)); in snl_attr_copy_struct()
801 snl_attr_dup_struct(struct snl_state *ss, struct nlattr *nla, in snl_attr_dup_struct() argument
804 void *ptr = snl_allocz(ss, NLA_DATA_LEN(nla)); in snl_attr_dup_struct()
850 _cb_p_bitset(struct snl_state *ss __unused, void *_target) in _cb_p_bitset()
884 snl_attr_get_bitset_c(struct snl_state *ss, struct nlattr *nla, in snl_attr_get_bitset_c() argument
891 if (!snl_parse_header(ss, NLA_DATA(nla), NLA_DATA_LEN(nla), p, _target)) in snl_attr_get_bitset_c()
899 snl_field_get_uint8(struct snl_state *ss __unused, void *src, void *target) in snl_field_get_uint8()
905 snl_field_get_uint16(struct snl_state *ss __unused, void *src, void *target) in snl_field_get_uint16()
911 snl_field_get_uint32(struct snl_state *ss __unused, void *src, void *target) in snl_field_get_uint32()
917 snl_field_get_ptr(struct snl_state *ss __unused, void *src, void *target) in snl_field_get_ptr()
956 snl_parse_errmsg(struct snl_state *ss, struct nlmsghdr *hdr, struct snl_errmsg_data *e) in snl_parse_errmsg() argument
959 return (snl_parse_nlmsg(ss, hdr, &snl_errmsg_parser, e)); in snl_parse_errmsg()
967 snl_parse_fields(ss, (struct nlmsghdr *)errmsg, hdrlen, ps->fp, ps->fp_size, e); in snl_parse_errmsg()
968 return (snl_parse_attrs_raw(ss, attr_head, attr_len, ps->np, ps->np_size, e)); in snl_parse_errmsg()
972 snl_read_reply_code(struct snl_state *ss, uint32_t nlmsg_seq, struct snl_errmsg_data *e) in snl_read_reply_code() argument
974 struct nlmsghdr *hdr = snl_read_reply(ss, nlmsg_seq); in snl_read_reply_code()
979 if (!snl_parse_errmsg(ss, hdr, e)) in snl_read_reply_code()
997 parse_cmsg(struct snl_state *ss, const struct msghdr *msg, struct snl_msg_info *attrs) in parse_cmsg() argument
1008 return (snl_parse_attrs_raw(ss, (struct nlattr *)data, len, ps->np, ps->np_size, attrs)); in parse_cmsg()
1018 snl_read_reply_multi(struct snl_state *ss, uint32_t nlmsg_seq, struct snl_errmsg_data *e) in snl_read_reply_multi() argument
1020 struct nlmsghdr *hdr = snl_read_reply(ss, nlmsg_seq); in snl_read_reply_multi()
1025 if (!snl_parse_errmsg(ss, hdr, e)) in snl_read_reply_multi()
1028 snl_parse_nlmsg(ss, hdr, &snl_donemsg_parser, e); in snl_read_reply_multi()
1042 struct snl_state *ss; member
1047 snl_init_writer(struct snl_state *ss, struct snl_writer *nw) in snl_init_writer() argument
1050 nw->base = (char *)snl_allocz(ss, nw->size); in snl_init_writer()
1059 nw->ss = ss; in snl_init_writer()
1073 if (snl_allocz(nw->ss, new_size) == NULL) { in snl_realloc_msg_buffer()
1079 void *new_base = nw->ss->lb->base; in snl_realloc_msg_buffer()
1296 hdr->nlmsg_seq = snl_get_seq(nw->ss); in snl_finalize_msg()
1312 return (snl_send(nw->ss, nw->base, offset)); in snl_send_msgs()