github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/tools/syz-declextract/testdata/netlink.c (about) 1 // Copyright 2024 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 #include "include/netlink.h" 5 #include "include/uapi/netlink_family.h" 6 7 // These consts are defined not in uapi .h, so the descriptions should contain 8 // values for them rather than includes. 9 enum netlink_foo_nested_attrs { 10 NETLINK_FOO_NESTED_ATTR1, 11 NETLINK_FOO_NESTED_ATTR2, 12 }; 13 14 static netlink_foo_struct2 var; 15 16 const struct nla_policy foo_genl_nested_policy[] = { 17 [NETLINK_FOO_NESTED_ATTR1] = { .type = NLA_U32 }, 18 [NETLINK_FOO_NESTED_ATTR2] = { .type = NLA_U32 }, 19 }; 20 21 const struct nla_policy foo_genl_policy[] = { 22 [NETLINK_FOO_ATTR1] = { .type = NLA_U32 }, 23 [NETLINK_FOO_ATTR2] = { .type = NLA_STRING, .len = 10 }, 24 [NETLINK_FOO_ATTR3] = { .type = NLA_NESTED }, 25 [NETLINK_FOO_ATTR4] = NLA_POLICY_NESTED(foo_genl_nested_policy), 26 [NETLINK_FOO_ATTR5] = { .len = sizeof(struct netlink_foo_struct1) }, 27 [NETLINK_FOO_ATTR6] = { .len = sizeof(netlink_foo_struct2) * 10 }, 28 [NETLINK_FOO_ATTR7] = { .len = sizeof(var) }, 29 }; 30 31 const struct nla_policy foo_dump_genl_policy[] = { 32 [NETLINK_FOO_ATTR1] = { .type = NLA_U32 }, 33 }; 34 35 const struct nla_policy genl_policy_reject_all[] = { 36 { .type = NLA_REJECT }, 37 { .type = NLA_REJECT }, 38 }; 39 40 const struct nla_policy policy_forward_decl[10]; 41 42 static void foo_cmd() {} 43 static void bar_cmd() {} 44 45 static const struct genl_ops foo_ops[] = { 46 { 47 .cmd = NETLINK_FOO_CMD_FOO, 48 .flags = GENL_ADMIN_PERM, 49 .doit = foo_cmd, 50 }, 51 { 52 .cmd = NETLINK_FOO_CMD_BAR, 53 .flags = GENL_UNS_ADMIN_PERM, 54 .doit = bar_cmd, 55 }, 56 { 57 .cmd = NETLINK_FOO_CMD_BAR, 58 .flags = GENL_UNS_ADMIN_PERM, 59 .dumpit = bar_cmd, 60 .policy = foo_dump_genl_policy, 61 }, 62 }; 63 64 static struct genl_family foo_family = { 65 .ops = foo_ops, 66 .n_ops = ARRAY_SIZE(foo_ops), 67 .name = "foo family", 68 .policy = foo_genl_policy, 69 }; 70 71 enum { 72 NETLINK_BAR_CMD_FOO, 73 }; 74 75 static void bar_pre_doit() {} 76 static void bar_doit() {} 77 static void bar_post_doit() {} 78 79 static const struct genl_split_ops bar_ops[] = { 80 { 81 .cmd = NETLINK_BAR_CMD_FOO, 82 .pre_doit = bar_pre_doit, 83 .doit = bar_doit, 84 .post_doit = bar_post_doit, 85 }, 86 }; 87 88 struct genl_family bar_family = { 89 .split_ops = bar_ops, 90 .n_split_ops = ARRAY_SIZE(bar_ops), 91 .name = "BAR", 92 .policy = foo_genl_policy, 93 }; 94 95 struct genl_family noops_family = { 96 .name = "NOOPS", 97 }; 98 99 enum netlink_nopolicy_cmds { 100 NETLINK_NOPOLICY_CMD, 101 }; 102 103 static const struct genl_ops nopolicy_ops[] = { 104 { 105 .cmd = NETLINK_NOPOLICY_CMD, 106 .doit = foo_cmd, 107 }, 108 }; 109 110 struct genl_family nopolicy_family = { 111 .name = "nopolicy", 112 .ops = nopolicy_ops, 113 .n_ops = ARRAY_SIZE(nopolicy_ops), 114 };