Debian Codegraph @

src/bus/bus.h

raw
1 #pragma once
2
3 /*
4 * Bus Context
5 */
6
7 #include <c-rbtree.h>
8 #include <c-stdaux.h>
9 #include <stdlib.h>
10 #include <sys/types.h>
11 #include "bus/listener.h"
12 #include "bus/match.h"
13 #include "bus/name.h"
14 #include "bus/peer.h"
15 #include "util/metrics.h"
16 #include "util/user.h"
17
18 enum {
19 _BUS_E_SUCCESS,
20
21 BUS_E_FAILURE,
22 };
23
24 enum {
25 BUS_LOG_POLICY_TYPE_INTERNAL,
26 BUS_LOG_POLICY_TYPE_SELINUX,
27 BUS_LOG_POLICY_TYPE_APPARMOR,
28 };
29
30 typedef struct Bus Bus;
31 typedef struct Log Log;
32 typedef struct Message Message;
33 typedef struct User User;
34
35 struct Bus {
36 Log *log;
37 User *user;
38 pid_t pid;
39 int pid_fd;
40 gid_t *gids;
41 size_t n_gids;
42 char *seclabel;
43 size_t n_seclabel;
44 char machine_id[33];
45 char guid[16];
46
47 UserRegistry users;
48 NameRegistry names;
49 MatchCounters match_counters;
50 MatchRegistry wildcard_matches;
51 MatchRegistry sender_matches;
52 PeerRegistry peers;
53
54 uint64_t n_monitors;
55 uint64_t listener_ids;
56 uint64_t activation_ids;
57 uint64_t stats_ids;
58
59 Metrics metrics;
60 };
61
62 #define BUS_NULL(_x) { \
63 .pid_fd = -1, \
64 .users = USER_REGISTRY_NULL, \
65 .names = NAME_REGISTRY_INIT, \
66 .match_counters = MATCH_COUNTERS_INIT, \
67 .wildcard_matches = MATCH_REGISTRY_INIT((_x).wildcard_matches), \
68 .sender_matches = MATCH_REGISTRY_INIT((_x).sender_matches), \
69 .peers = PEER_REGISTRY_INIT, \
70 .metrics = METRICS_INIT(CLOCK_THREAD_CPUTIME_ID), \
71 }
72
73 int bus_init(Bus *bus,
74 Log *log,
75 const char *machine_id,
76 unsigned int max_bytes,
77 unsigned int max_fds,
78 unsigned int max_matches,
79 unsigned int max_objects);
80 void bus_deinit(Bus *bus);
81
82 Peer *bus_find_peer_by_name(Bus *bus, Name **namep, const char *name);
83 void bus_get_monitor_destinations(Bus *bus, CList *destinations, Peer *sender, MessageMetadata *metadata);
84 void bus_get_broadcast_destinations(Bus *bus, CList *destinations, MatchRegistry *matches, Peer *sender, MessageMetadata *metadata);
85
86 void bus_log_append_receiver(Bus *bus, uint64_t receiver_id, NameSet *receiver_names, const char *receiver_label);
87 void bus_log_append_sender(Bus *bus, uint64_t sender_id, NameSet *sender_names, const char *sender_label);
88 void bus_log_append_transaction(Bus *bus, uint64_t sender_id, uint64_t receiver_id, NameSet *sender_names, NameSet *receiver_names, const char *sender_label, const char *receiver_label, Message *message);
89 void bus_log_append_policy_send(Bus *bus, int policy_type, uint64_t sender_id, uint64_t receiver_id, NameSet *sender_names, NameSet *receiver_names, const char *sender_label, const char *receiver_label, Message *message);
90 void bus_log_append_policy_receive(Bus *bus, int policy_type, uint64_t sender_id, uint64_t receiver_id, NameSet *sender_names, NameSet *receievr_names, Message *message);