]>
git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_pbr.c
1 /* Zebra Policy Based Routing (PBR) main handling.
2 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * This file is part of FRR.
6 * FRR is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * FRR is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with FRR; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include "zebra/zebra_pbr.h"
32 /* static function declarations */
34 /* Private functions */
36 /* Public functions */
37 void zebra_pbr_rules_free(void *arg
)
39 struct zebra_pbr_rule
*rule
;
41 rule
= (struct zebra_pbr_rule
*)arg
;
43 kernel_del_pbr_rule(rule
, NULL
);
44 XFREE(MTYPE_TMP
, rule
);
47 uint32_t zebra_pbr_rules_hash_key(void *arg
)
49 struct zebra_pbr_rule
*rule
;
52 rule
= (struct zebra_pbr_rule
*)arg
;
53 key
= jhash_3words(rule
->seq
, rule
->priority
, rule
->action
.table
,
54 prefix_hash_key(&rule
->filter
.src_ip
));
55 return jhash_3words(rule
->filter
.src_port
, rule
->filter
.dst_port
,
56 prefix_hash_key(&rule
->filter
.dst_ip
), key
);
59 int zebra_pbr_rules_hash_equal(const void *arg1
, const void *arg2
)
61 const struct zebra_pbr_rule
*r1
, *r2
;
63 r1
= (const struct zebra_pbr_rule
*)arg1
;
64 r2
= (const struct zebra_pbr_rule
*)arg2
;
66 if (r1
->seq
!= r2
->seq
)
69 if (r1
->priority
!= r2
->priority
)
72 if (r1
->action
.table
!= r2
->action
.table
)
75 if (r1
->filter
.src_port
!= r2
->filter
.src_port
)
78 if (r1
->filter
.dst_port
!= r2
->filter
.dst_port
)
81 if (!prefix_same(&r1
->filter
.src_ip
, &r2
->filter
.src_ip
))
84 if (!prefix_same(&r1
->filter
.dst_ip
, &r2
->filter
.dst_ip
))
90 static void *pbr_rule_alloc_intern(void *arg
)
92 struct zebra_pbr_rule
*zpr
;
93 struct zebra_pbr_rule
*new;
95 zpr
= (struct zebra_pbr_rule
*)arg
;
97 new = XCALLOC(MTYPE_TMP
, sizeof(*new));
99 memcpy(new, zpr
, sizeof(*zpr
));
104 void zebra_pbr_add_rule(struct zebra_ns
*zns
, struct zebra_pbr_rule
*rule
,
105 struct interface
*ifp
)
107 (void)hash_get(zns
->rules_hash
, rule
, pbr_rule_alloc_intern
);
108 kernel_add_pbr_rule(rule
, ifp
);
111 void zebra_pbr_del_rule(struct zebra_ns
*zns
, struct zebra_pbr_rule
*rule
,
112 struct interface
*ifp
)
114 struct zebra_pbr_rule
*lookup
;
116 lookup
= hash_lookup(zns
->rules_hash
, rule
);
117 kernel_del_pbr_rule(rule
, ifp
);
120 XFREE(MTYPE_TMP
, lookup
);
122 zlog_warn("%s: Rule being deleted we know nothing about",
123 __PRETTY_FUNCTION__
);
127 * Handle success or failure of rule (un)install in the kernel.
129 void kernel_pbr_rule_add_del_status(struct zebra_pbr_rule
*rule
,
130 struct interface
*ifp
,
131 enum southbound_results res
)
136 * Handle rule delete notification from kernel.
138 int kernel_pbr_rule_del(struct zebra_pbr_rule
*rule
, struct interface
*ifp
)