Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: PBR - netlink interaction and basic definitions #3

Merged
merged 1 commit into from
Feb 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions include/linux/fib_rules.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef __LINUX_FIB_RULES_H
#define __LINUX_FIB_RULES_H

#include <linux/types.h>
#include <linux/rtnetlink.h>

/* rule is permanent, and cannot be deleted */
#define FIB_RULE_PERMANENT 0x00000001
#define FIB_RULE_INVERT 0x00000002
#define FIB_RULE_UNRESOLVED 0x00000004
#define FIB_RULE_IIF_DETACHED 0x00000008
#define FIB_RULE_DEV_DETACHED FIB_RULE_IIF_DETACHED
#define FIB_RULE_OIF_DETACHED 0x00000010

/* try to find source address in routing lookups */
#define FIB_RULE_FIND_SADDR 0x00010000

struct fib_rule_hdr {
__u8 family;
__u8 dst_len;
__u8 src_len;
__u8 tos;

__u8 table;
__u8 res1; /* reserved */
__u8 res2; /* reserved */
__u8 action;

__u32 flags;
};

enum {
FRA_UNSPEC,
FRA_DST, /* destination address */
FRA_SRC, /* source address */
FRA_IIFNAME, /* interface name */
#define FRA_IFNAME FRA_IIFNAME
FRA_GOTO, /* target to jump to (FR_ACT_GOTO) */
FRA_UNUSED2,
FRA_PRIORITY, /* priority/preference */
FRA_UNUSED3,
FRA_UNUSED4,
FRA_UNUSED5,
FRA_FWMARK, /* mark */
FRA_FLOW, /* flow/class id */
FRA_UNUSED6,
FRA_SUPPRESS_IFGROUP,
FRA_SUPPRESS_PREFIXLEN,
FRA_TABLE, /* Extended table id */
FRA_FWMASK, /* mask for netfilter mark */
FRA_OIFNAME,
FRA_PAD,
FRA_L3MDEV, /* iif or oif is l3mdev goto its table */
__FRA_MAX
};

#define FRA_MAX (__FRA_MAX - 1)

enum {
FR_ACT_UNSPEC,
FR_ACT_TO_TBL, /* Pass to fixed table */
FR_ACT_GOTO, /* Jump to another rule */
FR_ACT_NOP, /* No operation */
FR_ACT_RES3,
FR_ACT_RES4,
FR_ACT_BLACKHOLE, /* Drop without notification */
FR_ACT_UNREACHABLE, /* Drop with ENETUNREACH */
FR_ACT_PROHIBIT, /* Drop with EACCES */
__FR_ACT_MAX,
};

#define FR_ACT_MAX (__FR_ACT_MAX - 1)

#endif
1 change: 1 addition & 0 deletions include/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ noinst_HEADERS += \
include/linux/neighbour.h \
include/linux/rtnetlink.h \
include/linux/socket.h \
include/linux/fib_rules.h \
# end
13 changes: 12 additions & 1 deletion zebra/kernel_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "zebra/kernel_netlink.h"
#include "zebra/rt_netlink.h"
#include "zebra/if_netlink.h"
#include "zebra/rule_netlink.h"

#ifndef SO_RCVBUFFORCE
#define SO_RCVBUFFORCE (33)
Expand Down Expand Up @@ -85,6 +86,9 @@ static const struct message nlmsg_str[] = {{RTM_NEWROUTE, "RTM_NEWROUTE"},
{RTM_NEWNEIGH, "RTM_NEWNEIGH"},
{RTM_DELNEIGH, "RTM_DELNEIGH"},
{RTM_GETNEIGH, "RTM_GETNEIGH"},
{RTM_NEWRULE, "RTM_NEWRULE"},
{RTM_DELRULE, "RTM_DELRULE"},
{RTM_GETRULE, "RTM_GETRULE"},
{0}};

static const struct message rtproto_str[] = {
Expand Down Expand Up @@ -262,6 +266,12 @@ static int netlink_information_fetch(struct sockaddr_nl *snl,
case RTM_DELNEIGH:
return netlink_neigh_change(snl, h, ns_id);
break;
case RTM_NEWRULE:
return netlink_rule_change(snl, h, ns_id, startup);
break;
case RTM_DELRULE:
return netlink_rule_change(snl, h, ns_id, startup);
break;
default:
if (IS_ZEBRA_DEBUG_KERNEL)
zlog_debug("Unknown netlink nlmsg_type %d vrf %u\n",
Expand Down Expand Up @@ -788,7 +798,8 @@ void kernel_init(struct zebra_ns *zns)
/* Initialize netlink sockets */
groups = RTMGRP_LINK | RTMGRP_IPV4_ROUTE | RTMGRP_IPV4_IFADDR
| RTMGRP_IPV6_ROUTE | RTMGRP_IPV6_IFADDR | RTMGRP_IPV4_MROUTE
| RTMGRP_NEIGH;
| RTMGRP_NEIGH
| RTNLGRP_IPV4_RULE | RTNLGRP_IPV6_RULE;

snprintf(zns->netlink.name, sizeof(zns->netlink.name),
"netlink-listen (NS %u)", zns->ns_id);
Expand Down
4 changes: 4 additions & 0 deletions zebra/rtread_getmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,8 @@ void neigh_read_for_vlan(struct zebra_ns *zns, struct interface *vlan_if)
{
}

void kernel_read_pbr_rules(struct zebra_ns *zns)
{
}

#endif /* SUNOS_5 */
7 changes: 7 additions & 0 deletions zebra/rtread_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

#include "vty.h"
#include "zebra/rt.h"
#include "zebra/zebra_pbr.h"
#include "zebra/rt_netlink.h"
#include "zebra/rule_netlink.h"

void route_read(struct zebra_ns *zns)
{
Expand Down Expand Up @@ -53,4 +55,9 @@ void neigh_read_for_vlan(struct zebra_ns *zns, struct interface *vlan_if)
netlink_neigh_read_for_vlan(zns, vlan_if);
}

void kernel_read_pbr_rules(struct zebra_ns *zns)
{
netlink_rules_read(zns);
}

#endif /* GNU_LINUX */
4 changes: 4 additions & 0 deletions zebra/rtread_sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ void neigh_read_for_vlan(struct zebra_ns *zns, struct interface *vlan_if)
{
}

void kernel_read_pbr_rules(struct zebra_ns *zns)
{
}

#endif /* !defined(GNU_LINUX) && !defined(SUNOS_5) */
Loading