From: osdl.net!shemminger Date: Tue, 31 Aug 2004 17:45:21 +0000 (+0000) Subject: make all filtering handles take const args. X-Git-Tag: v4.13.0~2257 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=6dc9f016347441fbf94cf851c054b0f45ba32c1c;p=mirror_iproute2.git make all filtering handles take const args. (Logical change 1.77) --- diff --git a/include/libnetlink.h b/include/libnetlink.h index 3ff0dfc2..3390d8b8 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -19,29 +19,30 @@ extern int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, in 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); -extern int rtnl_dump_filter(struct rtnl_handle *rth, - int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *), + +typedef int (*rtnl_filter_t)(const struct sockaddr_nl *, const struct nlmsghdr *n, void *); +extern int rtnl_dump_filter(struct rtnl_handle *rth, rtnl_filter_t filter, void *arg1, - int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), + rtnl_filter_t junk, void *arg2); extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, unsigned groups, struct nlmsghdr *answer, - int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), + rtnl_filter_t junk, void *jarg); -extern int rtnl_send(struct rtnl_handle *rth, char *buf, int); +extern int rtnl_send(struct rtnl_handle *rth, const char *buf, int); extern int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data); -extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen); +extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, int alen); extern int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data); -extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen); +extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, const void *data, int alen); extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len); extern int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len); -extern int rtnl_listen(struct rtnl_handle *, int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *), +extern int rtnl_listen(struct rtnl_handle *, rtnl_filter_t handler, void *jarg); -extern int rtnl_from_file(FILE *, int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *), +extern int rtnl_from_file(FILE *, rtnl_filter_t handler, void *jarg); #endif /* __LIBNETLINK_H__ */ diff --git a/include/ll_map.h b/include/ll_map.h index 739f157e..238a7287 100644 --- a/include/ll_map.h +++ b/include/ll_map.h @@ -1,9 +1,10 @@ #ifndef __LL_MAP_H__ #define __LL_MAP_H__ 1 -extern int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); +extern int ll_remember_index(const struct sockaddr_nl *who, const struct nlmsghdr *n, + void *arg); extern int ll_init_map(struct rtnl_handle *rth); -extern int ll_name_to_index(char *name); +extern int ll_name_to_index(const char *name); extern const char *ll_index_to_name(int idx); extern const char *ll_idx_n2a(int idx, char *buf); extern int ll_index_to_type(int idx); diff --git a/ip/ip_common.h b/ip/ip_common.h index 598c998a..c3599110 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -1,6 +1,11 @@ -extern int print_linkinfo(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); -extern int print_addrinfo(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); -extern int print_neigh(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); +extern int print_linkinfo(const struct sockaddr_nl *who, + const struct nlmsghdr *n, + void *arg); +extern int print_addrinfo(const struct sockaddr_nl *who, + const struct nlmsghdr *n, + void *arg); +extern int print_neigh(const struct sockaddr_nl *who, + const 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); @@ -8,7 +13,8 @@ extern void iplink_usage(void) __attribute__((noreturn)); extern void iproute_reset_filter(void); extern void ipaddr_reset_filter(int); extern void ipneigh_reset_filter(void); -extern int print_route(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); +extern int print_route(const struct sockaddr_nl *who, + const 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); diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 4bc63adf..01856c68 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -126,7 +126,7 @@ void print_queuelen(char *name) printf("qlen %d", ifr.ifr_qlen); } -int print_linkinfo(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +int print_linkinfo(const struct sockaddr_nl *who, const struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct ifinfomsg *ifi = NLMSG_DATA(n); @@ -275,7 +275,8 @@ static int flush_update(void) return 0; } -int print_addrinfo(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +int print_addrinfo(const struct sockaddr_nl *who, const struct nlmsghdr *n, + void *arg) { FILE *fp = (FILE*)arg; struct ifaddrmsg *ifa = NLMSG_DATA(n); @@ -465,7 +466,8 @@ int print_selected_addrinfo(int ifindex, struct nlmsg_list *ainfo, FILE *fp) } -int store_nlmsg(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +static int store_nlmsg(const struct sockaddr_nl *who, const struct nlmsghdr *n, + void *arg) { struct nlmsg_list **linfo = (struct nlmsg_list**)arg; struct nlmsg_list *h; diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c index 9ed6bbaf..46373e74 100644 --- a/ip/ipmonitor.c +++ b/ip/ipmonitor.c @@ -33,7 +33,8 @@ static void usage(void) } -int accept_msg(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +int accept_msg(const struct sockaddr_nl *who, + const struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; diff --git a/ip/ipneigh.c b/ip/ipneigh.c index f8c27900..c3105efa 100644 --- a/ip/ipneigh.c +++ b/ip/ipneigh.c @@ -217,7 +217,7 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv) } -int print_neigh(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +int print_neigh(const struct sockaddr_nl *who, const struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct ndmsg *r = NLMSG_DATA(n); diff --git a/ip/iproute.c b/ip/iproute.c index 48cd0754..c91075c9 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -103,7 +103,7 @@ static int flush_update(void) return 0; } -int print_route(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +int print_route(const struct sockaddr_nl *who, const struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct rtmsg *r = NLMSG_DATA(n); diff --git a/ip/iprule.c b/ip/iprule.c index 0edba5b5..a8bafc77 100644 --- a/ip/iprule.c +++ b/ip/iprule.c @@ -42,7 +42,8 @@ static void usage(void) exit(-1); } -int print_rule(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +static int print_rule(const struct sockaddr_nl *who, const struct nlmsghdr *n, + void *arg) { FILE *fp = (FILE*)arg; struct rtmsg *r = NLMSG_DATA(n); diff --git a/ip/rtmon.c b/ip/rtmon.c index d01bc635..76ef8b99 100644 --- a/ip/rtmon.c +++ b/ip/rtmon.c @@ -46,7 +46,8 @@ static void write_stamp(FILE *fp) fwrite((void*)n1, 1, NLMSG_ALIGN(n1->nlmsg_len), fp); } -static int dump_msg(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +static int dump_msg(const struct sockaddr_nl *who, const struct nlmsghdr *n, + void *arg) { FILE *fp = (FILE*)arg; if (!init_phase) diff --git a/ip/xfrm_policy.c b/ip/xfrm_policy.c index 07167da4..5c7059ee 100644 --- a/ip/xfrm_policy.c +++ b/ip/xfrm_policy.c @@ -334,7 +334,8 @@ static int xfrm_policy_filter_match(struct xfrm_userpolicy_info *xpinfo) return 1; } -int xfrm_policy_print(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +static int xfrm_policy_print(const struct sockaddr_nl *who, + const struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct xfrm_userpolicy_info *xpinfo = NLMSG_DATA(n); @@ -518,7 +519,9 @@ static int xfrm_policy_get(int argc, char **argv) * With an existing policy of nlmsg, make new nlmsg for deleting the policy * and store it to buffer. */ -int xfrm_policy_keep(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +static int xfrm_policy_keep(const struct sockaddr_nl *who, + const struct nlmsghdr *n, + void *arg) { struct xfrm_buffer *xb = (struct xfrm_buffer *)arg; struct rtnl_handle *rth = xb->rth; diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c index 6aa991f1..d6d21438 100644 --- a/ip/xfrm_state.c +++ b/ip/xfrm_state.c @@ -371,7 +371,9 @@ static int xfrm_selector_iszero(struct xfrm_selector *s) return (memcmp(&s0, s, sizeof(s0)) == 0); } -int xfrm_state_print(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +static int xfrm_state_print(const struct sockaddr_nl *who, + const struct nlmsghdr *n, + void *arg) { FILE *fp = (FILE*)arg; struct xfrm_usersa_info *xsinfo = NLMSG_DATA(n); @@ -511,7 +513,9 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete) * With an existing state of nlmsg, make new nlmsg for deleting the state * and store it to buffer. */ -int xfrm_state_keep(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +static int xfrm_state_keep(const struct sockaddr_nl *who, + const struct nlmsghdr *n, + void *arg) { struct xfrm_buffer *xb = (struct xfrm_buffer *)arg; struct rtnl_handle *rth = xb->rth; diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 76fedee1..45f293db 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -105,7 +105,7 @@ int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) return sendto(rth->fd, (void*)&req, sizeof(req), 0, (struct sockaddr*)&nladdr, sizeof(nladdr)); } -int rtnl_send(struct rtnl_handle *rth, char *buf, int len) +int rtnl_send(struct rtnl_handle *rth, const char *buf, int len) { struct sockaddr_nl nladdr; @@ -140,9 +140,9 @@ int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) } int rtnl_dump_filter(struct rtnl_handle *rth, - int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *), + rtnl_filter_t filter, void *arg1, - int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), + rtnl_filter_t junk, void *arg2) { char buf[16384]; @@ -224,7 +224,7 @@ skip_it: int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, unsigned groups, struct nlmsghdr *answer, - int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), + rtnl_filter_t junk, void *jarg) { int status; @@ -341,8 +341,8 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, } int rtnl_listen(struct rtnl_handle *rtnl, - int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *), - void *jarg) + rtnl_filter_t handler, + void *jarg) { int status; struct nlmsghdr *h; @@ -414,9 +414,8 @@ int rtnl_listen(struct rtnl_handle *rtnl, } } -int rtnl_from_file(FILE *rtnl, - int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *), - void *jarg) +int rtnl_from_file(FILE *rtnl, rtnl_filter_t handler, + void *jarg) { int status; struct sockaddr_nl nladdr; @@ -486,7 +485,8 @@ int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data) return 0; } -int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen) +int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, + int alen) { int len = RTA_LENGTH(alen); struct rtattr *rta; @@ -520,7 +520,8 @@ int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data) return 0; } -int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen) +int rta_addattr_l(struct rtattr *rta, int maxlen, int type, + const void *data, int alen) { struct rtattr *subrta; int len = RTA_LENGTH(alen); @@ -537,7 +538,6 @@ int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen return 0; } - int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) { while (RTA_OK(rta, len)) { diff --git a/lib/ll_map.c b/lib/ll_map.c index e5a95e6a..e5798d36 100644 --- a/lib/ll_map.c +++ b/lib/ll_map.c @@ -35,7 +35,7 @@ struct idxmap static struct idxmap *idxmap[16]; -int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +int ll_remember_index(const struct sockaddr_nl *who, const struct nlmsghdr *n, void *arg) { int h; struct ifinfomsg *ifi = NLMSG_DATA(n); @@ -131,7 +131,7 @@ unsigned ll_index_to_flags(int idx) return 0; } -int ll_name_to_index(char *name) +int ll_name_to_index(const char *name) { static char ncache[16]; static int icache; diff --git a/misc/ifstat.c b/misc/ifstat.c index b4a6d1d1..54afce4f 100644 --- a/misc/ifstat.c +++ b/misc/ifstat.c @@ -77,7 +77,7 @@ int match(char *id) return 0; } -int get_nlmsg(struct sockaddr_nl *who, struct nlmsghdr *m, void *arg) +int get_nlmsg(const struct sockaddr_nl *who, const struct nlmsghdr *m, void *arg) { struct ifinfomsg *ifi = NLMSG_DATA(m); struct rtattr * tb[IFLA_MAX+1]; diff --git a/tc/tc_class.c b/tc/tc_class.c index 154c2d10..d3d8bbca 100644 --- a/tc/tc_class.c +++ b/tc/tc_class.c @@ -176,7 +176,8 @@ void print_class_tcstats(FILE *fp, struct tc_stats *st) int filter_ifindex; __u32 filter_qdisc; -int print_class(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +static int print_class(const struct sockaddr_nl *who, + const struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct tcmsg *t = NLMSG_DATA(n); @@ -250,7 +251,7 @@ int print_class(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) fprintf(fp, "\n"); } } - if (q && tb[TCA_XSTATS]) { + if (q && tb[TCA_XSTATS] && q->print_xstats) { q->print_xstats(q, fp, tb[TCA_XSTATS]); fprintf(fp, "\n"); } diff --git a/tc/tc_util.c b/tc/tc_util.c index 5545478f..5cc9e38a 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -418,7 +418,7 @@ int action_a2n(char *arg, int *result) return 0; } -void print_tm(FILE * f, struct tcf_t *tm) +void print_tm(FILE * f, const struct tcf_t *tm) { int hz = get_hz(); if (tm->install != 0) diff --git a/tc/tc_util.h b/tc/tc_util.h index 3a257608..62a6c8cb 100644 --- a/tc/tc_util.h +++ b/tc/tc_util.h @@ -9,7 +9,7 @@ struct qdisc_util { struct qdisc_util *next; - char id[16]; + const char *id; int (*parse_qopt)(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n); int (*print_qopt)(struct qdisc_util *qu, FILE *f, struct rtattr *opt); int (*print_xstats)(struct qdisc_util *qu, FILE *f, struct rtattr *xstats); @@ -58,7 +58,7 @@ extern char * sprint_tc_classid(__u32 h, char *buf); extern char * sprint_usecs(__u32 usecs, char *buf); extern char * sprint_percent(__u32 percent, char *buf); -extern void print_tcstats(FILE *fp, struct tc_stats *st); +extern void print_tcstats_attr(FILE *fp, const struct rtattr *ts); extern int get_tc_classid(__u32 *h, const char *str); extern int print_tc_classid(char *buf, int len, __u32 h); @@ -70,11 +70,13 @@ extern int parse_police(int *, char ***, int, struct nlmsghdr *); extern char *action_n2a(int action, char *buf, int len); extern int action_a2n(char *arg, int *result); extern int act_parse_police(struct action_util *a,int *, char ***, int, struct nlmsghdr *); -extern int print_police(struct action_util *a,FILE *f, struct rtattr *tb); -extern int police_print_xstats(struct action_util *a,FILE *f, struct rtattr *tb); -extern int tc_print_action(FILE *f, struct rtattr *tb); -extern int tc_print_ipt(FILE *f, struct rtattr *tb); +extern int print_police(struct action_util *a, FILE *f, + struct rtattr *tb); +extern int police_print_xstats(struct action_util *a,FILE *f, + struct rtattr *tb); +extern int tc_print_action(FILE *f, const struct rtattr *tb); +extern int tc_print_ipt(FILE *f, const struct rtattr *tb); extern int parse_action(int *, char ***, int, struct nlmsghdr *); -extern void print_tm(FILE *f, struct tcf_t *tm); +extern void print_tm(FILE *f, const struct tcf_t *tm); #endif