mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
parser: ip size encoding should be an enum, not the ip size
According to the protocol expected by the kernel, the field representing the ip size should be an enum instead of the actual ip size. This is more future-proof. Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
This commit is contained in:
parent
989501428e
commit
2a885872a3
2 changed files with 7 additions and 3 deletions
|
@ -552,14 +552,14 @@ std::string gen_ip_cond(const struct ip_address ip)
|
|||
int i;
|
||||
if (ip.family == AF_INET) {
|
||||
/* add a byte containing the size of the following ip */
|
||||
oss << "\\x04";
|
||||
oss << "\\x" << std::setfill('0') << std::setw(2) << std::hex << IPV4_SIZE;
|
||||
|
||||
u8 *byte = (u8 *) &ip.address.address_v4; /* in network byte order */
|
||||
for (i = 0; i < 4; i++)
|
||||
oss << "\\x" << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned int>(byte[i]);
|
||||
} else {
|
||||
/* add a byte containing the size of the following ip */
|
||||
oss << "\\x10";
|
||||
oss << "\\x" << std::setfill('0') << std::setw(2) << std::hex << IPV6_SIZE;
|
||||
for (i = 0; i < 16; ++i)
|
||||
oss << "\\x" << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned int>(ip.address.address_v6[i]);
|
||||
}
|
||||
|
@ -601,7 +601,7 @@ void network_rule::gen_ip_conds(std::ostringstream &oss, ip_conds entry, bool is
|
|||
oss << gen_ip_cond(entry.ip);
|
||||
} else {
|
||||
/* encode 0 to indicate there's no ip (ip size) */
|
||||
oss << "\\x00";
|
||||
oss << "\\x" << std::setfill('0') << std::setw(2) << std::hex << ANON_SIZE;
|
||||
}
|
||||
|
||||
oss << "\\-x01"; /* oob separator */
|
||||
|
|
|
@ -79,6 +79,10 @@
|
|||
#define CMD_LISTEN 2
|
||||
#define CMD_OPT 4
|
||||
|
||||
#define ANON_SIZE 0
|
||||
#define IPV4_SIZE 1
|
||||
#define IPV6_SIZE 2
|
||||
|
||||
struct network_tuple {
|
||||
const char *family_name;
|
||||
unsigned int family;
|
||||
|
|
Loading…
Add table
Reference in a new issue