Lines Matching full:ss
129 typedef void snl_parse_field_f(struct snl_state *ss, void *hdr, void *target);
136 typedef bool snl_parse_attr_f(struct snl_state *ss, struct nlattr *attr,
150 typedef bool snl_parse_post_f(struct snl_state *ss, void *target);
201 snl_allocz(struct snl_state *ss, int len) in snl_allocz() argument
203 void *data = lb_allocz(ss->lb, len); in snl_allocz()
206 uint32_t size = ss->lb->size * 2; in snl_allocz()
214 lb->next = ss->lb; in snl_allocz()
215 ss->lb = lb; in snl_allocz()
216 data = lb_allocz(ss->lb, len); in snl_allocz()
224 snl_clear_lb(struct snl_state *ss) in snl_clear_lb() argument
226 struct linear_buffer *lb = ss->lb; in snl_clear_lb()
230 ss->lb->next = NULL; in snl_clear_lb()
240 snl_free(struct snl_state *ss) in snl_free() argument
242 if (ss->init_done) { in snl_free()
243 close(ss->fd); in snl_free()
244 if (ss->buf != NULL) in snl_free()
245 free(ss->buf); in snl_free()
246 if (ss->lb != NULL) { in snl_free()
247 snl_clear_lb(ss); in snl_free()
248 lb_free(ss->lb); in snl_free()
254 snl_init(struct snl_state *ss, int netlink_family) in snl_init() argument
256 memset(ss, 0, sizeof(*ss)); in snl_init()
258 ss->fd = socket(AF_NETLINK, SOCK_RAW, netlink_family); in snl_init()
259 if (ss->fd == -1) in snl_init()
261 ss->init_done = true; in snl_init()
265 if (setsockopt(ss->fd, SOL_NETLINK, NETLINK_EXT_ACK, &val, optlen) == -1) { in snl_init()
266 snl_free(ss); in snl_init()
271 if (getsockopt(ss->fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, &optlen) == -1) { in snl_init()
272 snl_free(ss); in snl_init()
276 ss->bufsize = rcvbuf; in snl_init()
277 ss->buf = (char *)malloc(ss->bufsize); in snl_init()
278 if (ss->buf == NULL) { in snl_init()
279 snl_free(ss); in snl_init()
283 ss->lb = lb_init(SCRATCH_BUFFER_SIZE); in snl_init()
284 if (ss->lb == NULL) { in snl_init()
285 snl_free(ss); in snl_init()
293 snl_send(struct snl_state *ss, void *data, int sz) in snl_send() argument
295 return (send(ss->fd, data, sz, 0) == sz); in snl_send()
299 snl_send_message(struct snl_state *ss, struct nlmsghdr *hdr) in snl_send_message() argument
303 return (send(ss->fd, hdr, sz, 0) == sz); in snl_send_message()
307 snl_get_seq(struct snl_state *ss) in snl_get_seq() argument
309 return (++ss->seq); in snl_get_seq()
319 static inline bool parse_cmsg(struct snl_state *ss, const struct msghdr *msg,
323 snl_read_message_dbg(struct snl_state *ss, struct snl_msg_info *cinfo) in snl_read_message_dbg() argument
327 if (ss->off == ss->datalen) { in snl_read_message_dbg()
332 .iov_base = ss->buf, in snl_read_message_dbg()
333 .iov_len = ss->bufsize, in snl_read_message_dbg()
343 ss->off = 0; in snl_read_message_dbg()
344 ss->datalen = 0; in snl_read_message_dbg()
346 ssize_t datalen = recvmsg(ss->fd, &msg, 0); in snl_read_message_dbg()
348 ss->datalen = datalen; in snl_read_message_dbg()
349 parse_cmsg(ss, &msg, cinfo); in snl_read_message_dbg()
355 struct nlmsghdr *hdr = (struct nlmsghdr *)(void *)&ss->buf[ss->off]; in snl_read_message_dbg()
356 ss->off += NLMSG_ALIGN(hdr->nlmsg_len); in snl_read_message_dbg()
362 snl_read_message(struct snl_state *ss) in snl_read_message() argument
364 if (ss->off == ss->datalen) { in snl_read_message()
367 .iov_base = ss->buf, in snl_read_message()
368 .iov_len = ss->bufsize, in snl_read_message()
376 ss->off = 0; in snl_read_message()
377 ss->datalen = 0; in snl_read_message()
379 ssize_t datalen = recvmsg(ss->fd, &msg, 0); in snl_read_message()
381 ss->datalen = datalen; in snl_read_message()
387 struct nlmsghdr *hdr = (struct nlmsghdr *)(void *)&ss->buf[ss->off]; in snl_read_message()
388 ss->off += NLMSG_ALIGN(hdr->nlmsg_len); in snl_read_message()
393 snl_read_reply(struct snl_state *ss, uint32_t nlmsg_seq) in snl_read_reply() argument
397 while ((hdr = snl_read_message(ss)) != NULL) { in snl_read_reply()
447 snl_parse_attrs_raw(struct snl_state *ss, struct nlattr *nla_head, int len, in snl_parse_attrs_raw() argument
459 if (!s->cb(ss, nla, s->arg, ptr)) in snl_parse_attrs_raw()
467 snl_parse_attrs(struct snl_state *ss, struct nlmsghdr *hdr, int hdrlen, in snl_parse_attrs() argument
474 return (snl_parse_attrs_raw(ss, nla_head, len, ps, pslen, target)); in snl_parse_attrs()
478 snl_parse_fields(struct snl_state *ss, struct nlmsghdr *hdr, int hdrlen __unused, in snl_parse_fields() argument
486 fp->cb(ss, src, dst); in snl_parse_fields()
491 snl_parse_header(struct snl_state *ss, void *hdr, int len, in snl_parse_header() argument
497 snl_parse_fields(ss, (struct nlmsghdr *)hdr, parser->in_hdr_size, in snl_parse_header()
501 bool result = snl_parse_attrs_raw(ss, nla_head, len - parser->in_hdr_size, in snl_parse_header()
505 result = parser->cb_post(ss, target); in snl_parse_header()
511 snl_parse_nlmsg(struct snl_state *ss, struct nlmsghdr *hdr, in snl_parse_nlmsg() argument
514 return (snl_parse_header(ss, hdr + 1, hdr->nlmsg_len - sizeof(*hdr), parser, target)); in snl_parse_nlmsg()
518 snl_attr_get_flag(struct snl_state *ss __unused, struct nlattr *nla, const void *arg __unused, in snl_attr_get_flag()
529 snl_attr_get_bytes(struct snl_state *ss __unused, struct nlattr *nla, const void *arg, in snl_attr_get_bytes()
541 snl_attr_get_bool(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_bool()
552 snl_attr_get_uint8(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_uint8()
563 snl_attr_get_uint16(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_uint16()
574 snl_attr_get_uint32(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_uint32()
585 snl_attr_get_uint64(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_uint64()
596 snl_attr_get_int8(struct snl_state *ss, struct nlattr *nla, const void *arg, in snl_attr_get_int8() argument
599 return (snl_attr_get_uint8(ss, nla, arg, target)); in snl_attr_get_int8()
603 snl_attr_get_int16(struct snl_state *ss, struct nlattr *nla, const void *arg, in snl_attr_get_int16() argument
606 return (snl_attr_get_uint16(ss, nla, arg, target)); in snl_attr_get_int16()
610 snl_attr_get_int32(struct snl_state *ss, struct nlattr *nla, const void *arg, in snl_attr_get_int32() argument
613 return (snl_attr_get_uint32(ss, nla, arg, target)); in snl_attr_get_int32()
617 snl_attr_get_int64(struct snl_state *ss, struct nlattr *nla, const void *arg, in snl_attr_get_int64() argument
620 return (snl_attr_get_uint64(ss, nla, arg, target)); in snl_attr_get_int64()
624 snl_attr_get_string(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_string()
637 snl_attr_get_stringn(struct snl_state *ss, struct nlattr *nla, in snl_attr_get_stringn() argument
642 char *buf = (char *)snl_allocz(ss, maxlen + 1); in snl_attr_get_stringn()
653 snl_attr_copy_string(struct snl_state *ss, struct nlattr *nla, in snl_attr_copy_string() argument
658 if (snl_attr_get_string(ss, nla, NULL, &tmp)) { in snl_attr_copy_string()
666 snl_attr_dup_string(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_dup_string()
672 char *buf = (char *)snl_allocz(ss, maxlen); in snl_attr_dup_string()
683 snl_attr_get_nested(struct snl_state *ss, struct nlattr *nla, const void *arg, void *target) in snl_attr_get_nested() argument
688 return (snl_parse_header(ss, NLA_DATA(nla), NLA_DATA_LEN(nla), p, target)); in snl_attr_get_nested()
697 snl_attr_get_parray_sz(struct snl_state *ss, struct nlattr *container_nla, in snl_attr_get_parray_sz() argument
708 array->items = (void **)snl_allocz(ss, size * sizeof(void *)); in snl_attr_get_parray_sz()
725 void *item = snl_allocz(ss, p->out_size); in snl_attr_get_parray_sz()
733 if (!(snl_parse_header(ss, data, data_len, p, item))) in snl_attr_get_parray_sz()
738 void **new_array = (void **)snl_allocz(ss, new_size *sizeof(void *)); in snl_attr_get_parray_sz()
758 snl_attr_get_parray(struct snl_state *ss, struct nlattr *nla, const void *arg, void *target) in snl_attr_get_parray() argument
760 return (snl_attr_get_parray_sz(ss, nla, 8, arg, target)); in snl_attr_get_parray()
764 snl_attr_get_nla(struct snl_state *ss __unused, struct nlattr *nla, in snl_attr_get_nla()
772 snl_attr_dup_nla(struct snl_state *ss, struct nlattr *nla, in snl_attr_dup_nla() argument
775 void *ptr = snl_allocz(ss, nla->nla_len); in snl_attr_dup_nla()
786 snl_attr_copy_struct(struct snl_state *ss, struct nlattr *nla, in snl_attr_copy_struct() argument
789 void *ptr = snl_allocz(ss, NLA_DATA_LEN(nla)); in snl_attr_copy_struct()
800 snl_attr_dup_struct(struct snl_state *ss, struct nlattr *nla, in snl_attr_dup_struct() argument
803 void *ptr = snl_allocz(ss, NLA_DATA_LEN(nla)); in snl_attr_dup_struct()
849 _cb_p_bitset(struct snl_state *ss __unused, void *_target) in _cb_p_bitset()
883 snl_attr_get_bitset_c(struct snl_state *ss, struct nlattr *nla, in snl_attr_get_bitset_c() argument
890 if (!snl_parse_header(ss, NLA_DATA(nla), NLA_DATA_LEN(nla), p, _target)) in snl_attr_get_bitset_c()
898 snl_field_get_uint8(struct snl_state *ss __unused, void *src, void *target) in snl_field_get_uint8()
904 snl_field_get_uint16(struct snl_state *ss __unused, void *src, void *target) in snl_field_get_uint16()
910 snl_field_get_uint32(struct snl_state *ss __unused, void *src, void *target) in snl_field_get_uint32()
916 snl_field_get_ptr(struct snl_state *ss __unused, void *src, void *target) in snl_field_get_ptr()
955 snl_parse_errmsg(struct snl_state *ss, struct nlmsghdr *hdr, struct snl_errmsg_data *e) in snl_parse_errmsg() argument
958 return (snl_parse_nlmsg(ss, hdr, &snl_errmsg_parser, e)); in snl_parse_errmsg()
966 snl_parse_fields(ss, (struct nlmsghdr *)errmsg, hdrlen, ps->fp, ps->fp_size, e); in snl_parse_errmsg()
967 return (snl_parse_attrs_raw(ss, attr_head, attr_len, ps->np, ps->np_size, e)); in snl_parse_errmsg()
971 snl_read_reply_code(struct snl_state *ss, uint32_t nlmsg_seq, struct snl_errmsg_data *e) in snl_read_reply_code() argument
973 struct nlmsghdr *hdr = snl_read_reply(ss, nlmsg_seq); in snl_read_reply_code()
978 if (!snl_parse_errmsg(ss, hdr, e)) in snl_read_reply_code()
996 parse_cmsg(struct snl_state *ss, const struct msghdr *msg, struct snl_msg_info *attrs) in parse_cmsg() argument
1007 return (snl_parse_attrs_raw(ss, (struct nlattr *)data, len, ps->np, ps->np_size, attrs)); in parse_cmsg()
1017 snl_read_reply_multi(struct snl_state *ss, uint32_t nlmsg_seq, struct snl_errmsg_data *e) in snl_read_reply_multi() argument
1019 struct nlmsghdr *hdr = snl_read_reply(ss, nlmsg_seq); in snl_read_reply_multi()
1024 if (!snl_parse_errmsg(ss, hdr, e)) in snl_read_reply_multi()
1027 snl_parse_nlmsg(ss, hdr, &snl_donemsg_parser, e); in snl_read_reply_multi()
1041 struct snl_state *ss; member
1046 snl_init_writer(struct snl_state *ss, struct snl_writer *nw) in snl_init_writer() argument
1049 nw->base = (char *)snl_allocz(ss, nw->size); in snl_init_writer()
1058 nw->ss = ss; in snl_init_writer()
1072 if (snl_allocz(nw->ss, new_size) == NULL) { in snl_realloc_msg_buffer()
1078 void *new_base = nw->ss->lb->base; in snl_realloc_msg_buffer()
1295 hdr->nlmsg_seq = snl_get_seq(nw->ss); in snl_finalize_msg()
1311 return (snl_send(nw->ss, nw->base, offset)); in snl_send_msgs()