^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * net/sched/cls_rsvp.h Template file for RSVPv[46] classifiers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) Comparing to general packet classification problem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) RSVP needs only sevaral relatively simple rules:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * (dst, protocol) are always specified,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) so that we are able to hash them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * src may be exact, or may be wildcard, so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) we can keep a hash table plus one wildcard entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * source port (or flow label) is important only if src is given.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) IMPLEMENTATION.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) We use a two level hash table: The top level is keyed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) destination address and protocol ID, every bucket contains a list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) of "rsvp sessions", identified by destination address, protocol and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) DPI(="Destination Port ID"): triple (key, mask, offset).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) Every bucket has a smaller hash table keyed by source address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) (cf. RSVP flowspec) and one wildcard entry for wildcard reservations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) Every bucket is again a list of "RSVP flows", selected by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) source address and SPI(="Source Port ID" here rather than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) "security parameter index"): triple (key, mask, offset).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) NOTE 1. All the packets with IPv6 extension headers (but AH and ESP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) and all fragmented packets go to the best-effort traffic class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) NOTE 2. Two "port id"'s seems to be redundant, rfc2207 requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) only one "Generalized Port Identifier". So that for classic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ah, esp (and udp,tcp) both *pi should coincide or one of them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) should be wildcard.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) At first sight, this redundancy is just a waste of CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) resources. But DPI and SPI add the possibility to assign different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) priorities to GPIs. Look also at note 4 about tunnels below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) NOTE 3. One complication is the case of tunneled packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) We implement it as following: if the first lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) matches a special session with "tunnelhdr" value not zero,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) flowid doesn't contain the true flow ID, but the tunnel ID (1...255).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) In this case, we pull tunnelhdr bytes and restart lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) with tunnel ID added to the list of keys. Simple and stupid 8)8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) It's enough for PIMREG and IPIP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) NOTE 4. Two GPIs make it possible to parse even GRE packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) F.e. DPI can select ETH_P_IP (and necessary flags to make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) tunnelhdr correct) in GRE protocol field and SPI matches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) GRE key. Is it not nice? 8)8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) Well, as result, despite its simplicity, we get a pretty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) powerful classification engine. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct rsvp_head {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u32 tmap[256/32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u32 hgenerator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) u8 tgenerator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct rsvp_session __rcu *ht[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct rsvp_session {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct rsvp_session __rcu *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) __be32 dst[RSVP_DST_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct tc_rsvp_gpi dpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) u8 protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) u8 tunnelid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* 16 (src,sport) hash slots, and one wildcard source slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct rsvp_filter __rcu *ht[16 + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct rsvp_filter {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct rsvp_filter __rcu *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) __be32 src[RSVP_DST_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct tc_rsvp_gpi spi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u8 tunnelhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct tcf_result res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct tcf_exts exts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) u32 handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct rsvp_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct rcu_work rwork;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static inline unsigned int hash_dst(__be32 *dst, u8 protocol, u8 tunnelid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) unsigned int h = (__force __u32)dst[RSVP_DST_LEN - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) h ^= h>>16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) h ^= h>>8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return (h ^ protocol ^ tunnelid) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static inline unsigned int hash_src(__be32 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned int h = (__force __u32)src[RSVP_DST_LEN-1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) h ^= h>>16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) h ^= h>>8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) h ^= h>>4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return h & 0xF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define RSVP_APPLY_RESULT() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int r = tcf_exts_exec(skb, &f->exts, res); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (r < 0) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) continue; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) else if (r > 0) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return r; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int rsvp_classify(struct sk_buff *skb, const struct tcf_proto *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct tcf_result *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct rsvp_head *head = rcu_dereference_bh(tp->root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct rsvp_session *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct rsvp_filter *f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) unsigned int h1, h2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) __be32 *dst, *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) u8 protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) u8 tunnelid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) u8 *xprt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #if RSVP_DST_LEN == 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct ipv6hdr *nhptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (!pskb_network_may_pull(skb, sizeof(*nhptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) nhptr = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct iphdr *nhptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (!pskb_network_may_pull(skb, sizeof(*nhptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) nhptr = ip_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #if RSVP_DST_LEN == 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) src = &nhptr->saddr.s6_addr32[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) dst = &nhptr->daddr.s6_addr32[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) protocol = nhptr->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) xprt = ((u8 *)nhptr) + sizeof(struct ipv6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) src = &nhptr->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) dst = &nhptr->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) protocol = nhptr->protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) xprt = ((u8 *)nhptr) + (nhptr->ihl<<2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (ip_is_fragment(nhptr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) h1 = hash_dst(dst, protocol, tunnelid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) h2 = hash_src(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) for (s = rcu_dereference_bh(head->ht[h1]); s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) s = rcu_dereference_bh(s->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (dst[RSVP_DST_LEN-1] == s->dst[RSVP_DST_LEN - 1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) protocol == s->protocol &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) !(s->dpi.mask &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) (*(u32 *)(xprt + s->dpi.offset) ^ s->dpi.key)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #if RSVP_DST_LEN == 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) dst[0] == s->dst[0] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) dst[1] == s->dst[1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) dst[2] == s->dst[2] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) tunnelid == s->tunnelid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) for (f = rcu_dereference_bh(s->ht[h2]); f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) f = rcu_dereference_bh(f->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (src[RSVP_DST_LEN-1] == f->src[RSVP_DST_LEN - 1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) !(f->spi.mask & (*(u32 *)(xprt + f->spi.offset) ^ f->spi.key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #if RSVP_DST_LEN == 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) src[0] == f->src[0] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) src[1] == f->src[1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) src[2] == f->src[2]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) *res = f->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) RSVP_APPLY_RESULT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) matched:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (f->tunnelhdr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) tunnelid = f->res.classid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) nhptr = (void *)(xprt + f->tunnelhdr - sizeof(*nhptr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* And wildcard bucket... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) for (f = rcu_dereference_bh(s->ht[16]); f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) f = rcu_dereference_bh(f->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) *res = f->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) RSVP_APPLY_RESULT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) goto matched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static void rsvp_replace(struct tcf_proto *tp, struct rsvp_filter *n, u32 h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct rsvp_head *head = rtnl_dereference(tp->root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct rsvp_session *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct rsvp_filter __rcu **ins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct rsvp_filter *pins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) unsigned int h1 = h & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) unsigned int h2 = (h >> 8) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) for (s = rtnl_dereference(head->ht[h1]); s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) s = rtnl_dereference(s->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) for (ins = &s->ht[h2], pins = rtnl_dereference(*ins); ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) ins = &pins->next, pins = rtnl_dereference(*ins)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (pins->handle == h) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) RCU_INIT_POINTER(n->next, pins->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) rcu_assign_pointer(*ins, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* Something went wrong if we are trying to replace a non-existant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * node. Mind as well halt instead of silently failing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) BUG_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static void *rsvp_get(struct tcf_proto *tp, u32 handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct rsvp_head *head = rtnl_dereference(tp->root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct rsvp_session *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct rsvp_filter *f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) unsigned int h1 = handle & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) unsigned int h2 = (handle >> 8) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (h2 > 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) for (s = rtnl_dereference(head->ht[h1]); s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) s = rtnl_dereference(s->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) for (f = rtnl_dereference(s->ht[h2]); f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) f = rtnl_dereference(f->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (f->handle == handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static int rsvp_init(struct tcf_proto *tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct rsvp_head *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) data = kzalloc(sizeof(struct rsvp_head), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) rcu_assign_pointer(tp->root, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static void __rsvp_delete_filter(struct rsvp_filter *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) tcf_exts_destroy(&f->exts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) tcf_exts_put_net(&f->exts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) kfree(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static void rsvp_delete_filter_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct rsvp_filter *f = container_of(to_rcu_work(work),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) struct rsvp_filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) rwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) __rsvp_delete_filter(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static void rsvp_delete_filter(struct tcf_proto *tp, struct rsvp_filter *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) tcf_unbind_filter(tp, &f->res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /* all classifiers are required to call tcf_exts_destroy() after rcu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * grace period, since converted-to-rcu actions are relying on that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * in cleanup() callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (tcf_exts_get_net(&f->exts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) tcf_queue_work(&f->rwork, rsvp_delete_filter_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) __rsvp_delete_filter(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static void rsvp_destroy(struct tcf_proto *tp, bool rtnl_held,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct rsvp_head *data = rtnl_dereference(tp->root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) int h1, h2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) for (h1 = 0; h1 < 256; h1++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct rsvp_session *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) while ((s = rtnl_dereference(data->ht[h1])) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) RCU_INIT_POINTER(data->ht[h1], s->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) for (h2 = 0; h2 <= 16; h2++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct rsvp_filter *f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) while ((f = rtnl_dereference(s->ht[h2])) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) rcu_assign_pointer(s->ht[h2], f->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) rsvp_delete_filter(tp, f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) kfree_rcu(s, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) kfree_rcu(data, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static int rsvp_delete(struct tcf_proto *tp, void *arg, bool *last,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) bool rtnl_held, struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct rsvp_head *head = rtnl_dereference(tp->root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct rsvp_filter *nfp, *f = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct rsvp_filter __rcu **fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) unsigned int h = f->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct rsvp_session __rcu **sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct rsvp_session *nsp, *s = f->sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) int i, h1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) fp = &s->ht[(h >> 8) & 0xFF];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) for (nfp = rtnl_dereference(*fp); nfp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) fp = &nfp->next, nfp = rtnl_dereference(*fp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (nfp == f) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) RCU_INIT_POINTER(*fp, f->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) rsvp_delete_filter(tp, f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* Strip tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) for (i = 0; i <= 16; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (s->ht[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /* OK, session has no flows */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) sp = &head->ht[h & 0xFF];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) for (nsp = rtnl_dereference(*sp); nsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) sp = &nsp->next, nsp = rtnl_dereference(*sp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (nsp == s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) RCU_INIT_POINTER(*sp, s->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) kfree_rcu(s, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) *last = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) for (h1 = 0; h1 < 256; h1++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (rcu_access_pointer(head->ht[h1])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) *last = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static unsigned int gen_handle(struct tcf_proto *tp, unsigned salt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct rsvp_head *data = rtnl_dereference(tp->root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) int i = 0xFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) while (i-- > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) u32 h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if ((data->hgenerator += 0x10000) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) data->hgenerator = 0x10000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) h = data->hgenerator|salt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (!rsvp_get(tp, h))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) return h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static int tunnel_bts(struct rsvp_head *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) int n = data->tgenerator >> 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) u32 b = 1 << (data->tgenerator & 0x1F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (data->tmap[n] & b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) data->tmap[n] |= b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static void tunnel_recycle(struct rsvp_head *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct rsvp_session __rcu **sht = data->ht;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) u32 tmap[256/32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) int h1, h2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) memset(tmap, 0, sizeof(tmap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) for (h1 = 0; h1 < 256; h1++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct rsvp_session *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) for (s = rtnl_dereference(sht[h1]); s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) s = rtnl_dereference(s->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) for (h2 = 0; h2 <= 16; h2++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct rsvp_filter *f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) for (f = rtnl_dereference(s->ht[h2]); f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) f = rtnl_dereference(f->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (f->tunnelhdr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) data->tgenerator = f->res.classid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) tunnel_bts(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) memcpy(data->tmap, tmap, sizeof(tmap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static u32 gen_tunnel(struct rsvp_head *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) int i, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) for (k = 0; k < 2; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) for (i = 255; i > 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (++data->tgenerator == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) data->tgenerator = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (tunnel_bts(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) return data->tgenerator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) tunnel_recycle(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static const struct nla_policy rsvp_policy[TCA_RSVP_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) [TCA_RSVP_CLASSID] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) [TCA_RSVP_DST] = { .len = RSVP_DST_LEN * sizeof(u32) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) [TCA_RSVP_SRC] = { .len = RSVP_DST_LEN * sizeof(u32) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) [TCA_RSVP_PINFO] = { .len = sizeof(struct tc_rsvp_pinfo) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static int rsvp_change(struct net *net, struct sk_buff *in_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct tcf_proto *tp, unsigned long base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) u32 handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct nlattr **tca,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) void **arg, bool ovr, bool rtnl_held,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct rsvp_head *data = rtnl_dereference(tp->root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct rsvp_filter *f, *nfp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct rsvp_filter __rcu **fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct rsvp_session *nsp, *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) struct rsvp_session __rcu **sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) struct tc_rsvp_pinfo *pinfo = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct nlattr *opt = tca[TCA_OPTIONS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) struct nlattr *tb[TCA_RSVP_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) struct tcf_exts e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) unsigned int h1, h2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) __be32 *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (opt == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return handle ? -EINVAL : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) err = nla_parse_nested_deprecated(tb, TCA_RSVP_MAX, opt, rsvp_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) err = tcf_exts_init(&e, net, TCA_RSVP_ACT, TCA_RSVP_POLICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e, ovr, true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) goto errout2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) f = *arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (f) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /* Node exists: adjust only classid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct rsvp_filter *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (f->handle != handle && handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) goto errout2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) n = kmemdup(f, sizeof(*f), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (!n) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) goto errout2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) err = tcf_exts_init(&n->exts, net, TCA_RSVP_ACT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) TCA_RSVP_POLICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) kfree(n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) goto errout2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if (tb[TCA_RSVP_CLASSID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) n->res.classid = nla_get_u32(tb[TCA_RSVP_CLASSID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) tcf_bind_filter(tp, &n->res, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) tcf_exts_change(&n->exts, &e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) rsvp_replace(tp, n, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) /* Now more serious part... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) goto errout2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (tb[TCA_RSVP_DST] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) goto errout2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) f = kzalloc(sizeof(struct rsvp_filter), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) if (f == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) goto errout2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) err = tcf_exts_init(&f->exts, net, TCA_RSVP_ACT, TCA_RSVP_POLICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) h2 = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) if (tb[TCA_RSVP_SRC]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) memcpy(f->src, nla_data(tb[TCA_RSVP_SRC]), sizeof(f->src));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) h2 = hash_src(f->src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (tb[TCA_RSVP_PINFO]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) pinfo = nla_data(tb[TCA_RSVP_PINFO]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) f->spi = pinfo->spi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) f->tunnelhdr = pinfo->tunnelhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) if (tb[TCA_RSVP_CLASSID])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) f->res.classid = nla_get_u32(tb[TCA_RSVP_CLASSID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) dst = nla_data(tb[TCA_RSVP_DST]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) h1 = hash_dst(dst, pinfo ? pinfo->protocol : 0, pinfo ? pinfo->tunnelid : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if ((f->handle = gen_handle(tp, h1 | (h2<<8))) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) if (f->tunnelhdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (f->res.classid > 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) if (f->res.classid == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) (f->res.classid = gen_tunnel(data)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) for (sp = &data->ht[h1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) (s = rtnl_dereference(*sp)) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) sp = &s->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (dst[RSVP_DST_LEN-1] == s->dst[RSVP_DST_LEN-1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) pinfo && pinfo->protocol == s->protocol &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) memcmp(&pinfo->dpi, &s->dpi, sizeof(s->dpi)) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) #if RSVP_DST_LEN == 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) dst[0] == s->dst[0] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) dst[1] == s->dst[1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) dst[2] == s->dst[2] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) pinfo->tunnelid == s->tunnelid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) insert:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /* OK, we found appropriate session */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) fp = &s->ht[h2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) f->sess = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (f->tunnelhdr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) tcf_bind_filter(tp, &f->res, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) tcf_exts_change(&f->exts, &e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) fp = &s->ht[h2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) for (nfp = rtnl_dereference(*fp); nfp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) fp = &nfp->next, nfp = rtnl_dereference(*fp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) __u32 mask = nfp->spi.mask & f->spi.mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (mask != f->spi.mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) RCU_INIT_POINTER(f->next, nfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) rcu_assign_pointer(*fp, f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) *arg = f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) /* No session found. Create new one. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) s = kzalloc(sizeof(struct rsvp_session), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (s == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) memcpy(s->dst, dst, sizeof(s->dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (pinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) s->dpi = pinfo->dpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) s->protocol = pinfo->protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) s->tunnelid = pinfo->tunnelid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) sp = &data->ht[h1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) for (nsp = rtnl_dereference(*sp); nsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) sp = &nsp->next, nsp = rtnl_dereference(*sp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if ((nsp->dpi.mask & s->dpi.mask) != s->dpi.mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) RCU_INIT_POINTER(s->next, nsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) rcu_assign_pointer(*sp, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) goto insert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) tcf_exts_destroy(&f->exts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) kfree(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) errout2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) tcf_exts_destroy(&e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) static void rsvp_walk(struct tcf_proto *tp, struct tcf_walker *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) bool rtnl_held)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) struct rsvp_head *head = rtnl_dereference(tp->root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) unsigned int h, h1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (arg->stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) for (h = 0; h < 256; h++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) struct rsvp_session *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) for (s = rtnl_dereference(head->ht[h]); s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) s = rtnl_dereference(s->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) for (h1 = 0; h1 <= 16; h1++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) struct rsvp_filter *f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) for (f = rtnl_dereference(s->ht[h1]); f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) f = rtnl_dereference(f->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (arg->count < arg->skip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) arg->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if (arg->fn(tp, f, arg) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) arg->stop = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) arg->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) static int rsvp_dump(struct net *net, struct tcf_proto *tp, void *fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) struct sk_buff *skb, struct tcmsg *t, bool rtnl_held)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) struct rsvp_filter *f = fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) struct rsvp_session *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) struct nlattr *nest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) struct tc_rsvp_pinfo pinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (f == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) s = f->sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) t->tcm_handle = f->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) if (nest == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (nla_put(skb, TCA_RSVP_DST, sizeof(s->dst), &s->dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) pinfo.dpi = s->dpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) pinfo.spi = f->spi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) pinfo.protocol = s->protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) pinfo.tunnelid = s->tunnelid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) pinfo.tunnelhdr = f->tunnelhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) pinfo.pad = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (nla_put(skb, TCA_RSVP_PINFO, sizeof(pinfo), &pinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (f->res.classid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) nla_put_u32(skb, TCA_RSVP_CLASSID, f->res.classid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) if (((f->handle >> 8) & 0xFF) != 16 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) nla_put(skb, TCA_RSVP_SRC, sizeof(f->src), f->src))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if (tcf_exts_dump(skb, &f->exts) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) nla_nest_end(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (tcf_exts_dump_stats(skb, &f->exts) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) nla_nest_cancel(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) static void rsvp_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) unsigned long base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) struct rsvp_filter *f = fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (f && f->res.classid == classid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) if (cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) __tcf_bind_filter(q, &f->res, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) __tcf_unbind_filter(q, &f->res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) static struct tcf_proto_ops RSVP_OPS __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) .kind = RSVP_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) .classify = rsvp_classify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) .init = rsvp_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) .destroy = rsvp_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) .get = rsvp_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) .change = rsvp_change,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) .delete = rsvp_delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) .walk = rsvp_walk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) .dump = rsvp_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) .bind_class = rsvp_bind_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) static int __init init_rsvp(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) return register_tcf_proto_ops(&RSVP_OPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) static void __exit exit_rsvp(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) unregister_tcf_proto_ops(&RSVP_OPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) module_init(init_rsvp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) module_exit(exit_rsvp)