31 #include <linux/types.h>
32 #include <linux/socket.h>
33 #include <linux/string.h>
36 #include <linux/in6.h>
37 #include <linux/slab.h>
62 static struct genl_family netlbl_mgmt_gnl_family = {
124 switch (entry->
type) {
146 addrmap = kzalloc(
sizeof(*addrmap),
GFP_KERNEL);
147 if (addrmap ==
NULL) {
151 INIT_LIST_HEAD(&addrmap->
list4);
152 INIT_LIST_HEAD(&addrmap->
list6);
187 #if IS_ENABLED(CONFIG_IPV6)
193 addrmap = kzalloc(
sizeof(*addrmap),
GFP_KERNEL);
194 if (addrmap ==
NULL) {
198 INIT_LIST_HEAD(&addrmap->
list4);
199 INIT_LIST_HEAD(&addrmap->
list6);
220 map->
list.addr.s6_addr32[0] &= mask->s6_addr32[0];
221 map->
list.addr.s6_addr32[1] &= mask->s6_addr32[1];
222 map->
list.addr.s6_addr32[2] &= mask->s6_addr32[2];
223 map->
list.addr.s6_addr32[3] &= mask->s6_addr32[3];
228 ret_val = netlbl_af6list_add(&map->
list, &addrmap->
list6);
266 static int netlbl_mgmt_listentry(
struct sk_buff *
skb,
273 #if IS_ENABLED(CONFIG_IPV6)
278 ret_val = nla_put_string(skb,
284 switch (entry->
type) {
299 addr_struct.s_addr = iter4->
addr;
305 addr_struct.s_addr = iter4->
mask;
316 switch (map4->
type) {
325 nla_nest_end(skb, nla_b);
327 #if IS_ENABLED(CONFIG_IPV6)
328 netlbl_af6list_foreach_rcu(iter6,
352 nla_nest_end(skb, nla_b);
356 nla_nest_end(skb, nla_a);
404 netlbl_netlink_auditinfo(skb, &audit_info);
406 return netlbl_mgmt_add_common(info, &audit_info);
427 netlbl_netlink_auditinfo(skb, &audit_info);
452 cb_arg->
seq, &netlbl_mgmt_gnl_family,
455 goto listall_cb_failure;
457 ret_val = netlbl_mgmt_listentry(cb_arg->
skb, entry);
459 goto listall_cb_failure;
462 return genlmsg_end(cb_arg->
skb, data);
465 genlmsg_cancel(cb_arg->
skb, data);
480 static int netlbl_mgmt_listall(
struct sk_buff *skb,
489 cb_arg.
seq = cb->
nlh->nlmsg_seq;
493 netlbl_mgmt_listall_cb,
496 cb->
args[0] = skip_bkt;
497 cb->
args[1] = skip_chain;
526 netlbl_netlink_auditinfo(skb, &audit_info);
528 return netlbl_mgmt_add_common(info, &audit_info);
541 static int netlbl_mgmt_removedef(
struct sk_buff *skb,
struct genl_info *info)
545 netlbl_netlink_auditinfo(skb, &audit_info);
571 data = genlmsg_put_reply(ans_skb, info, &netlbl_mgmt_gnl_family,
574 goto listdef_failure;
580 goto listdef_failure_lock;
582 ret_val = netlbl_mgmt_listentry(ans_skb, entry);
585 goto listdef_failure;
587 genlmsg_end(ans_skb, data);
588 return genlmsg_reply(ans_skb, info);
590 listdef_failure_lock:
609 static int netlbl_mgmt_protocols_cb(
struct sk_buff *skb,
620 goto protocols_cb_failure;
624 goto protocols_cb_failure;
626 return genlmsg_end(skb, data);
628 protocols_cb_failure:
629 genlmsg_cancel(skb, data);
642 static int netlbl_mgmt_protocols(
struct sk_buff *skb,
647 if (protos_sent == 0) {
648 if (netlbl_mgmt_protocols_cb(skb,
651 goto protocols_return;
654 if (protos_sent == 1) {
655 if (netlbl_mgmt_protocols_cb(skb,
658 goto protocols_return;
663 cb->
args[0] = protos_sent;
686 data = genlmsg_put_reply(ans_skb, info, &netlbl_mgmt_gnl_family,
689 goto version_failure;
691 ret_val = nla_put_u32(ans_skb,
695 goto version_failure;
697 genlmsg_end(ans_skb, data);
698 return genlmsg_reply(ans_skb, info);
710 static struct genl_ops netlbl_mgmt_genl_ops[] = {
714 .policy = netlbl_mgmt_genl_policy,
715 .doit = netlbl_mgmt_add,
721 .policy = netlbl_mgmt_genl_policy,
722 .doit = netlbl_mgmt_remove,
728 .policy = netlbl_mgmt_genl_policy,
730 .dumpit = netlbl_mgmt_listall,
735 .policy = netlbl_mgmt_genl_policy,
736 .doit = netlbl_mgmt_adddef,
742 .policy = netlbl_mgmt_genl_policy,
743 .doit = netlbl_mgmt_removedef,
749 .policy = netlbl_mgmt_genl_policy,
750 .doit = netlbl_mgmt_listdef,
756 .policy = netlbl_mgmt_genl_policy,
758 .dumpit = netlbl_mgmt_protocols,
763 .policy = netlbl_mgmt_genl_policy,
764 .doit = netlbl_mgmt_version,
784 netlbl_mgmt_genl_ops,
ARRAY_SIZE(netlbl_mgmt_genl_ops));