Add ip rule flush capabilty and fix all the prototype changes
because of that code rewrites the nlmsghdr. (Logical change 1.106)
This commit is contained in:
parent
7c8fdcd3be
commit
50772dc51a
|
|
@ -1,3 +1,12 @@
|
|||
2004-12-07 Stephen Hemminger <shemminger@osdl.org>
|
||||
|
||||
* Cleanup warning generated because ip_rule_flush needs to modify
|
||||
the netlink message
|
||||
|
||||
2004-12-07 Sven Anders <anders@anduras.de>
|
||||
|
||||
* Add ip rule flush
|
||||
|
||||
2004-10-19 Harald Welte <laforge@gnumonks.org>
|
||||
|
||||
* Replace rtstat (and ctstat) with new lnstat
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ extern void rtnl_close(struct rtnl_handle *rth);
|
|||
extern int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type);
|
||||
extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len);
|
||||
|
||||
typedef int (*rtnl_filter_t)(const struct sockaddr_nl *, const struct nlmsghdr *n, void *);
|
||||
typedef int (*rtnl_filter_t)(const struct sockaddr_nl *,
|
||||
struct nlmsghdr *n, void *);
|
||||
extern int rtnl_dump_filter(struct rtnl_handle *rth, rtnl_filter_t filter,
|
||||
void *arg1,
|
||||
rtnl_filter_t junk,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef __LL_MAP_H__
|
||||
#define __LL_MAP_H__ 1
|
||||
|
||||
extern int ll_remember_index(const struct sockaddr_nl *who, const struct nlmsghdr *n,
|
||||
void *arg);
|
||||
extern int ll_remember_index(const struct sockaddr_nl *who,
|
||||
struct nlmsghdr *n, void *arg);
|
||||
extern int ll_init_map(struct rtnl_handle *rth);
|
||||
extern int ll_name_to_index(const char *name);
|
||||
extern const char *ll_index_to_name(int idx);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
extern int print_linkinfo(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n,
|
||||
struct nlmsghdr *n,
|
||||
void *arg);
|
||||
extern int print_addrinfo(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n,
|
||||
struct nlmsghdr *n,
|
||||
void *arg);
|
||||
extern int print_neigh(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n, void *arg);
|
||||
struct nlmsghdr *n, void *arg);
|
||||
extern int ipaddr_list(int argc, char **argv);
|
||||
extern int ipaddr_list_link(int argc, char **argv);
|
||||
extern int iproute_monitor(int argc, char **argv);
|
||||
|
|
@ -14,7 +14,7 @@ extern void iproute_reset_filter(void);
|
|||
extern void ipaddr_reset_filter(int);
|
||||
extern void ipneigh_reset_filter(void);
|
||||
extern int print_route(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n, void *arg);
|
||||
struct nlmsghdr *n, void *arg);
|
||||
extern int do_ipaddr(int argc, char **argv);
|
||||
extern int do_iproute(int argc, char **argv);
|
||||
extern int do_iprule(int argc, char **argv);
|
||||
|
|
|
|||
|
|
@ -126,7 +126,8 @@ void print_queuelen(char *name)
|
|||
printf("qlen %d", ifr.ifr_qlen);
|
||||
}
|
||||
|
||||
int print_linkinfo(const struct sockaddr_nl *who, const struct nlmsghdr *n, void *arg)
|
||||
int print_linkinfo(const struct sockaddr_nl *who,
|
||||
struct nlmsghdr *n, void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
struct ifinfomsg *ifi = NLMSG_DATA(n);
|
||||
|
|
@ -275,7 +276,7 @@ static int flush_update(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int print_addrinfo(const struct sockaddr_nl *who, const struct nlmsghdr *n,
|
||||
int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
|
||||
void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
|
|
@ -466,7 +467,7 @@ int print_selected_addrinfo(int ifindex, struct nlmsg_list *ainfo, FILE *fp)
|
|||
}
|
||||
|
||||
|
||||
static int store_nlmsg(const struct sockaddr_nl *who, const struct nlmsghdr *n,
|
||||
static int store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n,
|
||||
void *arg)
|
||||
{
|
||||
struct nlmsg_list **linfo = (struct nlmsg_list**)arg;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ static void usage(void)
|
|||
|
||||
|
||||
int accept_msg(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n, void *arg)
|
||||
struct nlmsghdr *n, void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
|
|||
}
|
||||
|
||||
|
||||
int print_neigh(const struct sockaddr_nl *who, const struct nlmsghdr *n, void *arg)
|
||||
int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
struct ndmsg *r = NLMSG_DATA(n);
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ static int flush_update(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int print_route(const struct sockaddr_nl *who, const struct nlmsghdr *n, void *arg)
|
||||
int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
struct rtmsg *r = NLMSG_DATA(n);
|
||||
|
|
|
|||
68
ip/iprule.c
68
ip/iprule.c
|
|
@ -32,7 +32,7 @@ static void usage(void) __attribute__((noreturn));
|
|||
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: ip rule [ list | add | del ] SELECTOR ACTION\n");
|
||||
fprintf(stderr, "Usage: ip rule [ list | add | del | flush ] SELECTOR ACTION\n");
|
||||
fprintf(stderr, "SELECTOR := [ from PREFIX ] [ to PREFIX ] [ tos TOS ] [ fwmark FWMARK ]\n");
|
||||
fprintf(stderr, " [ dev STRING ] [ pref NUMBER ]\n");
|
||||
fprintf(stderr, "ACTION := [ table TABLE_ID ] [ nat ADDRESS ]\n");
|
||||
|
|
@ -42,7 +42,7 @@ static void usage(void)
|
|||
exit(-1);
|
||||
}
|
||||
|
||||
static int print_rule(const struct sockaddr_nl *who, const struct nlmsghdr *n,
|
||||
static int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n,
|
||||
void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
|
|
@ -160,7 +160,7 @@ static int print_rule(const struct sockaddr_nl *who, const struct nlmsghdr *n,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int iprule_list(int argc, char **argv)
|
||||
static int iprule_list(int argc, char **argv)
|
||||
{
|
||||
struct rtnl_handle rth;
|
||||
int af = preferred_family;
|
||||
|
|
@ -190,7 +190,7 @@ int iprule_list(int argc, char **argv)
|
|||
}
|
||||
|
||||
|
||||
int iprule_modify(int cmd, int argc, char **argv)
|
||||
static int iprule_modify(int cmd, int argc, char **argv)
|
||||
{
|
||||
int table_ok = 0;
|
||||
struct rtnl_handle rth;
|
||||
|
|
@ -303,6 +303,64 @@ int iprule_modify(int cmd, int argc, char **argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int flush_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
||||
{
|
||||
struct rtnl_handle rth;
|
||||
struct rtmsg *r = NLMSG_DATA(n);
|
||||
int len = n->nlmsg_len;
|
||||
struct rtattr * tb[RTA_MAX+1];
|
||||
|
||||
len -= NLMSG_LENGTH(sizeof(*r));
|
||||
if (len < 0)
|
||||
return -1;
|
||||
|
||||
memset(tb, 0, sizeof(tb));
|
||||
parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
|
||||
|
||||
if (tb[RTA_PRIORITY]) {
|
||||
n->nlmsg_type = RTM_DELRULE;
|
||||
n->nlmsg_flags = NLM_F_REQUEST;
|
||||
|
||||
if (rtnl_open(&rth, 0) < 0)
|
||||
return -1;
|
||||
|
||||
if (rtnl_talk(&rth, n, 0, 0, NULL, NULL, NULL) < 0)
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iprule_flush(int argc, char **argv)
|
||||
{
|
||||
struct rtnl_handle rth;
|
||||
int af = preferred_family;
|
||||
|
||||
if (af == AF_UNSPEC)
|
||||
af = AF_INET;
|
||||
|
||||
if (argc > 0) {
|
||||
fprintf(stderr, "\"ip rule flush\" need not any arguments.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rtnl_open(&rth, 0) < 0)
|
||||
return 1;
|
||||
|
||||
if (rtnl_wilddump_request(&rth, af, RTM_GETRULE) < 0) {
|
||||
perror("Cannot send dump request");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (rtnl_dump_filter(&rth, flush_rule, NULL, NULL, NULL) < 0) {
|
||||
fprintf(stderr, "Flush terminated\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int do_iprule(int argc, char **argv)
|
||||
{
|
||||
if (argc < 1) {
|
||||
|
|
@ -315,6 +373,8 @@ int do_iprule(int argc, char **argv)
|
|||
return iprule_modify(RTM_NEWRULE, argc-1, argv+1);
|
||||
} else if (matches(argv[0], "delete") == 0) {
|
||||
return iprule_modify(RTM_DELRULE, argc-1, argv+1);
|
||||
} else if (matches(argv[0], "flush") == 0) {
|
||||
return iprule_flush(argc-1, argv+1);
|
||||
} else if (matches(argv[0], "help") == 0)
|
||||
usage();
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ static void write_stamp(FILE *fp)
|
|||
fwrite((void*)n1, 1, NLMSG_ALIGN(n1->nlmsg_len), fp);
|
||||
}
|
||||
|
||||
static int dump_msg(const struct sockaddr_nl *who, const struct nlmsghdr *n,
|
||||
static int dump_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
|
||||
void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
|
|
|
|||
|
|
@ -336,7 +336,7 @@ static int xfrm_policy_filter_match(struct xfrm_userpolicy_info *xpinfo)
|
|||
}
|
||||
|
||||
static int xfrm_policy_print(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n, void *arg)
|
||||
struct nlmsghdr *n, void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
struct xfrm_userpolicy_info *xpinfo = NLMSG_DATA(n);
|
||||
|
|
@ -521,7 +521,7 @@ static int xfrm_policy_get(int argc, char **argv)
|
|||
* and store it to buffer.
|
||||
*/
|
||||
static int xfrm_policy_keep(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n,
|
||||
struct nlmsghdr *n,
|
||||
void *arg)
|
||||
{
|
||||
struct xfrm_buffer *xb = (struct xfrm_buffer *)arg;
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ static int xfrm_selector_iszero(struct xfrm_selector *s)
|
|||
}
|
||||
|
||||
static int xfrm_state_print(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n,
|
||||
struct nlmsghdr *n,
|
||||
void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
|
|
@ -517,7 +517,7 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete)
|
|||
* and store it to buffer.
|
||||
*/
|
||||
static int xfrm_state_keep(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n,
|
||||
struct nlmsghdr *n,
|
||||
void *arg)
|
||||
{
|
||||
struct xfrm_buffer *xb = (struct xfrm_buffer *)arg;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ struct idxmap
|
|||
|
||||
static struct idxmap *idxmap[16];
|
||||
|
||||
int ll_remember_index(const struct sockaddr_nl *who, const struct nlmsghdr *n, void *arg)
|
||||
int ll_remember_index(const struct sockaddr_nl *who,
|
||||
struct nlmsghdr *n, void *arg)
|
||||
{
|
||||
int h;
|
||||
struct ifinfomsg *ifi = NLMSG_DATA(n);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ struct ifstat_ent
|
|||
struct ifstat_ent *kern_db;
|
||||
struct ifstat_ent *hist_db;
|
||||
|
||||
int match(char *id)
|
||||
static int match(const char *id)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -77,7 +77,8 @@ int match(char *id)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int get_nlmsg(const struct sockaddr_nl *who, const struct nlmsghdr *m, void *arg)
|
||||
static int get_nlmsg(const struct sockaddr_nl *who,
|
||||
struct nlmsghdr *m, void *arg)
|
||||
{
|
||||
struct ifinfomsg *ifi = NLMSG_DATA(m);
|
||||
struct rtattr * tb[IFLA_MAX+1];
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ tc_print_action(FILE * f, const struct rtattr *arg)
|
|||
}
|
||||
|
||||
static int do_print_action(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n,
|
||||
struct nlmsghdr *n,
|
||||
void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ int filter_ifindex;
|
|||
__u32 filter_qdisc;
|
||||
|
||||
static int print_class(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n, void *arg)
|
||||
struct nlmsghdr *n, void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
struct tcmsg *t = NLMSG_DATA(n);
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ static __u32 filter_prio;
|
|||
static __u32 filter_protocol;
|
||||
|
||||
static int print_filter(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n,
|
||||
struct nlmsghdr *n,
|
||||
void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ void print_tcstats_attr(FILE *fp, const struct rtattr *rta)
|
|||
static int filter_ifindex;
|
||||
|
||||
static int print_qdisc(const struct sockaddr_nl *who,
|
||||
const struct nlmsghdr *n,
|
||||
struct nlmsghdr *n,
|
||||
void *arg)
|
||||
{
|
||||
FILE *fp = (FILE*)arg;
|
||||
|
|
|
|||
Loading…
Reference in New Issue