mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-01 14:55:10 +00:00
provide a mapping of sock type and name and a fn to look access the mapping
Signed-off-by: John Johansen <john.johansen@canonical.com> Acked-by: Seth Arnold <seth.arnold@canonical.com> Acked-by: Steve Beattie <steve@nxnw.org>
This commit is contained in:
@@ -35,23 +35,51 @@
|
|||||||
* have to make sure these are in order. This means we are more brittle
|
* have to make sure these are in order. This means we are more brittle
|
||||||
* but there isn't much we can do.
|
* but there isn't much we can do.
|
||||||
*/
|
*/
|
||||||
const char *sock_types[] = {
|
struct sock_type_map {
|
||||||
"none", /* 0 */
|
const char *name;
|
||||||
"stream", /* 1 [SOCK_STREAM] */
|
int value;
|
||||||
"dgram", /* 2 [SOCK_DGRAM] */
|
};
|
||||||
"raw", /* 3 [SOCK_RAW] */
|
|
||||||
"rdm", /* 4 [SOCK_RDM] */
|
struct sock_type_map sock_types[] = {
|
||||||
"seqpacket", /* 5 [SOCK_SEQPACKET] */
|
{ "none", 0 },
|
||||||
"dccp", /* 6 [SOCK_DCCP] */
|
{ "stream", SOCK_STREAM },
|
||||||
"invalid", /* 7 */
|
{ "dgram", SOCK_DGRAM },
|
||||||
"invalid", /* 8 */
|
{ "raw", SOCK_RAW },
|
||||||
"invalid", /* 9 */
|
{ "rdm", SOCK_RDM },
|
||||||
"packet", /* 10 [SOCK_PACKET] */
|
{ "seqpacket", SOCK_SEQPACKET },
|
||||||
|
{ "dccp", SOCK_DCCP },
|
||||||
|
{ "invalid", -1 },
|
||||||
|
{ "invalid", -1 },
|
||||||
|
{ "invalid", -1 },
|
||||||
|
{ "packet", SOCK_PACKET },
|
||||||
|
{ NULL, -1 },
|
||||||
/*
|
/*
|
||||||
* See comment above
|
* See comment above
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int net_find_type_val(const char *type)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; sock_types[i].name; i++) {
|
||||||
|
if (strcmp(sock_types[i].name, type) == 0)
|
||||||
|
return sock_types[i].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *net_find_type_name(int type)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; sock_types[i].name; i++) {
|
||||||
|
if (sock_types[i].value == type)
|
||||||
|
return sock_types[i].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
struct network_tuple {
|
struct network_tuple {
|
||||||
const char *family_name;
|
const char *family_name;
|
||||||
unsigned int family;
|
unsigned int family;
|
||||||
@@ -319,7 +347,7 @@ void __debug_network(unsigned int *array, const char *name)
|
|||||||
for (j = 0; j < count; j++) {
|
for (j = 0; j < count; j++) {
|
||||||
const char *type;
|
const char *type;
|
||||||
if (array[i] & (1 << j)) {
|
if (array[i] & (1 << j)) {
|
||||||
type = sock_types[j];
|
type = sock_types[j].name;
|
||||||
if (type)
|
if (type)
|
||||||
printf("%s ", type);
|
printf("%s ", type);
|
||||||
else
|
else
|
||||||
|
@@ -75,4 +75,7 @@ struct network {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int net_find_type_val(const char *type);
|
||||||
|
const char *net_find_type_name(int type);
|
||||||
|
|
||||||
#endif /* __AA_NETWORK_H */
|
#endif /* __AA_NETWORK_H */
|
||||||
|
Reference in New Issue
Block a user