Lines Matching refs:cp

143 static unsigned int ip_vs_conn_hashkey_conn(const struct ip_vs_conn *cp)
147 ip_vs_conn_fill_param(cp->ipvs, cp->af, cp->protocol,
148 &cp->caddr, cp->cport, NULL, 0, &p);
150 if (cp->pe) {
151 p.pe = cp->pe;
152 p.pe_data = cp->pe_data;
153 p.pe_data_len = cp->pe_data_len;
163 static inline int ip_vs_conn_hash(struct ip_vs_conn *cp)
168 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
172 hash = ip_vs_conn_hashkey_conn(cp);
175 spin_lock(&cp->lock);
177 if (!(cp->flags & IP_VS_CONN_F_HASHED)) {
178 cp->flags |= IP_VS_CONN_F_HASHED;
179 refcount_inc(&cp->refcnt);
180 hlist_add_head_rcu(&cp->c_list, &ip_vs_conn_tab[hash]);
188 spin_unlock(&cp->lock);
199 static inline int ip_vs_conn_unhash(struct ip_vs_conn *cp)
205 hash = ip_vs_conn_hashkey_conn(cp);
208 spin_lock(&cp->lock);
210 if (cp->flags & IP_VS_CONN_F_HASHED) {
211 hlist_del_rcu(&cp->c_list);
212 cp->flags &= ~IP_VS_CONN_F_HASHED;
213 refcount_dec(&cp->refcnt);
218 spin_unlock(&cp->lock);
227 static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)
232 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
233 return refcount_dec_if_one(&cp->refcnt);
235 hash = ip_vs_conn_hashkey_conn(cp);
238 spin_lock(&cp->lock);
240 if (cp->flags & IP_VS_CONN_F_HASHED) {
242 if (refcount_dec_if_one(&cp->refcnt)) {
243 hlist_del_rcu(&cp->c_list);
244 cp->flags &= ~IP_VS_CONN_F_HASHED;
249 spin_unlock(&cp->lock);
266 struct ip_vs_conn *cp;
272 hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[hash], c_list) {
273 if (p->cport == cp->cport && p->vport == cp->vport &&
274 cp->af == p->af &&
275 ip_vs_addr_equal(p->af, p->caddr, &cp->caddr) &&
276 ip_vs_addr_equal(p->af, p->vaddr, &cp->vaddr) &&
277 ((!p->cport) ^ (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
278 p->protocol == cp->protocol &&
279 cp->ipvs == p->ipvs) {
280 if (!__ip_vs_conn_get(cp))
284 return cp;
295 struct ip_vs_conn *cp;
297 cp = __ip_vs_conn_in_get(p);
298 if (!cp && atomic_read(&ip_vs_conn_no_cport_cnt)) {
301 cp = __ip_vs_conn_in_get(&cport_zero_p);
308 cp ? "hit" : "not hit");
310 return cp;
352 struct ip_vs_conn *cp;
358 hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[hash], c_list) {
360 if (cp->ipvs != p->ipvs)
362 if (p->pe == cp->pe && p->pe->ct_match(p, cp)) {
363 if (__ip_vs_conn_get(cp))
369 if (cp->af == p->af &&
370 ip_vs_addr_equal(p->af, p->caddr, &cp->caddr) &&
374 p->af, p->vaddr, &cp->vaddr) &&
375 p->vport == cp->vport && p->cport == cp->cport &&
376 cp->flags & IP_VS_CONN_F_TEMPLATE &&
377 p->protocol == cp->protocol &&
378 cp->ipvs == p->ipvs) {
379 if (__ip_vs_conn_get(cp))
383 cp = NULL;
392 cp ? "hit" : "not hit");
394 return cp;
404 struct ip_vs_conn *cp, *ret=NULL;
415 hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[hash], c_list) {
416 if (p->vport != cp->cport)
419 if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
420 sport = cp->vport;
421 saddr = &cp->vaddr;
423 sport = cp->dport;
424 saddr = &cp->daddr;
427 if (p->cport == sport && cp->af == p->af &&
428 ip_vs_addr_equal(p->af, p->vaddr, &cp->caddr) &&
430 p->protocol == cp->protocol &&
431 cp->ipvs == p->ipvs) {
432 if (!__ip_vs_conn_get(cp))
435 ret = cp;
468 static void __ip_vs_conn_put_timer(struct ip_vs_conn *cp)
470 unsigned long t = (cp->flags & IP_VS_CONN_F_ONE_PACKET) ?
471 0 : cp->timeout;
472 mod_timer(&cp->timer, jiffies+t);
474 __ip_vs_conn_put(cp);
477 void ip_vs_conn_put(struct ip_vs_conn *cp)
479 if ((cp->flags & IP_VS_CONN_F_ONE_PACKET) &&
480 (refcount_read(&cp->refcnt) == 1) &&
481 !timer_pending(&cp->timer))
483 ip_vs_conn_expire(&cp->timer);
485 __ip_vs_conn_put_timer(cp);
491 void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport)
493 if (ip_vs_conn_unhash(cp)) {
494 spin_lock_bh(&cp->lock);
495 if (cp->flags & IP_VS_CONN_F_NO_CPORT) {
497 cp->flags &= ~IP_VS_CONN_F_NO_CPORT;
498 cp->cport = cport;
500 spin_unlock_bh(&cp->lock);
503 ip_vs_conn_hash(cp);
512 static inline void ip_vs_bind_xmit(struct ip_vs_conn *cp)
514 switch (IP_VS_FWD_METHOD(cp)) {
516 cp->packet_xmit = ip_vs_nat_xmit;
521 if (cp->daf == AF_INET6)
522 cp->packet_xmit = ip_vs_tunnel_xmit_v6;
525 cp->packet_xmit = ip_vs_tunnel_xmit;
529 cp->packet_xmit = ip_vs_dr_xmit;
533 cp->packet_xmit = ip_vs_null_xmit;
537 cp->packet_xmit = ip_vs_bypass_xmit;
543 static inline void ip_vs_bind_xmit_v6(struct ip_vs_conn *cp)
545 switch (IP_VS_FWD_METHOD(cp)) {
547 cp->packet_xmit = ip_vs_nat_xmit_v6;
551 if (cp->daf == AF_INET6)
552 cp->packet_xmit = ip_vs_tunnel_xmit_v6;
554 cp->packet_xmit = ip_vs_tunnel_xmit;
558 cp->packet_xmit = ip_vs_dr_xmit_v6;
562 cp->packet_xmit = ip_vs_null_xmit;
566 cp->packet_xmit = ip_vs_bypass_xmit_v6;
584 ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
597 if (cp->protocol != IPPROTO_UDP)
599 flags = cp->flags;
611 cp->flags = flags;
612 cp->dest = dest;
617 ip_vs_proto_name(cp->protocol),
618 IP_VS_DBG_ADDR(cp->af, &cp->caddr), ntohs(cp->cport),
619 IP_VS_DBG_ADDR(cp->af, &cp->vaddr), ntohs(cp->vport),
620 IP_VS_DBG_ADDR(cp->daf, &cp->daddr), ntohs(cp->dport),
621 ip_vs_fwd_tag(cp), cp->state,
622 cp->flags, refcount_read(&cp->refcnt),
651 void ip_vs_try_bind_dest(struct ip_vs_conn *cp)
662 dest = ip_vs_find_dest(cp->ipvs, cp->af, cp->af, &cp->daddr,
663 cp->dport, &cp->vaddr, cp->vport,
664 cp->protocol, cp->fwmark, cp->flags);
668 spin_lock_bh(&cp->lock);
669 if (cp->dest) {
670 spin_unlock_bh(&cp->lock);
677 if (cp->app)
678 ip_vs_unbind_app(cp);
680 ip_vs_bind_dest(cp, dest);
681 spin_unlock_bh(&cp->lock);
684 cp->packet_xmit = NULL;
686 if (cp->af == AF_INET6)
687 ip_vs_bind_xmit_v6(cp);
690 ip_vs_bind_xmit(cp);
692 pd = ip_vs_proto_data_get(cp->ipvs, cp->protocol);
694 ip_vs_bind_app(cp, pd->pp);
704 static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)
706 struct ip_vs_dest *dest = cp->dest;
714 ip_vs_proto_name(cp->protocol),
715 IP_VS_DBG_ADDR(cp->af, &cp->caddr), ntohs(cp->cport),
716 IP_VS_DBG_ADDR(cp->af, &cp->vaddr), ntohs(cp->vport),
717 IP_VS_DBG_ADDR(cp->daf, &cp->daddr), ntohs(cp->dport),
718 ip_vs_fwd_tag(cp), cp->state,
719 cp->flags, refcount_read(&cp->refcnt),
723 if (!(cp->flags & IP_VS_CONN_F_TEMPLATE)) {
726 if (cp->flags & IP_VS_CONN_F_INACTIVE) {
814 struct ip_vs_conn *cp = container_of(head, struct ip_vs_conn,
817 ip_vs_pe_put(cp->pe);
818 kfree(cp->pe_data);
819 kmem_cache_free(ip_vs_conn_cachep, cp);
823 static void ip_vs_conn_del(struct ip_vs_conn *cp)
825 if (del_timer(&cp->timer)) {
826 /* Drop cp->control chain too */
827 if (cp->control)
828 cp->timeout = 0;
829 ip_vs_conn_expire(&cp->timer);
834 static void ip_vs_conn_del_put(struct ip_vs_conn *cp)
836 if (del_timer(&cp->timer)) {
837 /* Drop cp->control chain too */
838 if (cp->control)
839 cp->timeout = 0;
840 __ip_vs_conn_put(cp);
841 ip_vs_conn_expire(&cp->timer);
843 __ip_vs_conn_put(cp);
849 struct ip_vs_conn *cp = from_timer(cp, t, timer);
850 struct netns_ipvs *ipvs = cp->ipvs;
855 if (atomic_read(&cp->n_control))
859 if (likely(ip_vs_conn_unlink(cp))) {
860 struct ip_vs_conn *ct = cp->control;
863 del_timer(&cp->timer);
867 bool has_ref = !cp->timeout && __ip_vs_conn_get(ct);
869 ip_vs_control_del(cp);
881 if ((cp->flags & IP_VS_CONN_F_NFCT) &&
882 !(cp->flags & IP_VS_CONN_F_ONE_PACKET)) {
889 ip_vs_conn_drop_conntrack(cp);
892 if (unlikely(cp->app != NULL))
893 ip_vs_unbind_app(cp);
894 ip_vs_unbind_dest(cp);
895 if (cp->flags & IP_VS_CONN_F_NO_CPORT)
897 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
898 ip_vs_conn_rcu_free(&cp->rcu_head);
900 call_rcu(&cp->rcu_head, ip_vs_conn_rcu_free);
907 refcount_read(&cp->refcnt),
908 atomic_read(&cp->n_control));
910 refcount_inc(&cp->refcnt);
911 cp->timeout = 60*HZ;
914 ip_vs_sync_conn(ipvs, cp, sysctl_sync_threshold(ipvs));
916 __ip_vs_conn_put_timer(cp);
923 * - cp->timeout=0 indicates all conns from chain should be dropped but
926 void ip_vs_conn_expire_now(struct ip_vs_conn *cp)
931 if (timer_pending(&cp->timer) &&
932 time_after(cp->timer.expires, jiffies))
933 mod_timer_pending(&cp->timer, jiffies);
945 struct ip_vs_conn *cp;
950 cp = kmem_cache_alloc(ip_vs_conn_cachep, GFP_ATOMIC);
951 if (cp == NULL) {
956 INIT_HLIST_NODE(&cp->c_list);
957 timer_setup(&cp->timer, ip_vs_conn_expire, 0);
958 cp->ipvs = ipvs;
959 cp->af = p->af;
960 cp->daf = dest_af;
961 cp->protocol = p->protocol;
962 ip_vs_addr_set(p->af, &cp->caddr, p->caddr);
963 cp->cport = p->cport;
966 &cp->vaddr, p->vaddr);
967 cp->vport = p->vport;
968 ip_vs_addr_set(cp->daf, &cp->daddr, daddr);
969 cp->dport = dport;
970 cp->flags = flags;
971 cp->fwmark = fwmark;
974 cp->pe = p->pe;
975 cp->pe_data = p->pe_data;
976 cp->pe_data_len = p->pe_data_len;
978 cp->pe = NULL;
979 cp->pe_data = NULL;
980 cp->pe_data_len = 0;
982 spin_lock_init(&cp->lock);
989 refcount_set(&cp->refcnt, 1);
991 cp->control = NULL;
992 atomic_set(&cp->n_control, 0);
993 atomic_set(&cp->in_pkts, 0);
995 cp->packet_xmit = NULL;
996 cp->app = NULL;
997 cp->app_data = NULL;
999 cp->in_seq.delta = 0;
1000 cp->out_seq.delta = 0;
1007 cp->dest = NULL;
1008 ip_vs_bind_dest(cp, dest);
1011 cp->state = 0;
1012 cp->old_state = 0;
1013 cp->timeout = 3*HZ;
1014 cp->sync_endtime = jiffies & ~3UL;
1019 ip_vs_bind_xmit_v6(cp);
1022 ip_vs_bind_xmit(cp);
1025 ip_vs_bind_app(cp, pd->pp);
1035 cp->flags |= IP_VS_CONN_F_NFCT;
1038 ip_vs_conn_hash(cp);
1040 return cp;
1055 struct ip_vs_conn *cp;
1059 hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[idx], c_list) {
1065 return cp;
1086 struct ip_vs_conn *cp = v;
1097 e = rcu_dereference(hlist_next_rcu(&cp->c_list));
1103 hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[idx], c_list) {
1105 return cp;
1126 const struct ip_vs_conn *cp = v;
1132 if (!net_eq(cp->ipvs->net, net))
1134 if (cp->pe_data) {
1136 len = strlen(cp->pe->name);
1137 memcpy(pe_data + 1, cp->pe->name, len);
1140 len += cp->pe->show_pe_data(cp, pe_data + len);
1145 if (cp->daf == AF_INET6)
1146 snprintf(dbuf, sizeof(dbuf), "%pI6", &cp->daddr.in6);
1150 ntohl(cp->daddr.ip));
1153 if (cp->af == AF_INET6)
1156 ip_vs_proto_name(cp->protocol),
1157 &cp->caddr.in6, ntohs(cp->cport),
1158 &cp->vaddr.in6, ntohs(cp->vport),
1159 dbuf, ntohs(cp->dport),
1160 ip_vs_state_name(cp),
1161 jiffies_delta_to_msecs(cp->timer.expires -
1169 ip_vs_proto_name(cp->protocol),
1170 ntohl(cp->caddr.ip), ntohs(cp->cport),
1171 ntohl(cp->vaddr.ip), ntohs(cp->vport),
1172 dbuf, ntohs(cp->dport),
1173 ip_vs_state_name(cp),
1174 jiffies_delta_to_msecs(cp->timer.expires -
1204 const struct ip_vs_conn *cp = v;
1207 if (!net_eq(cp->ipvs->net, net))
1211 if (cp->daf == AF_INET6)
1212 snprintf(dbuf, sizeof(dbuf), "%pI6", &cp->daddr.in6);
1216 ntohl(cp->daddr.ip));
1219 if (cp->af == AF_INET6)
1222 ip_vs_proto_name(cp->protocol),
1223 &cp->caddr.in6, ntohs(cp->cport),
1224 &cp->vaddr.in6, ntohs(cp->vport),
1225 dbuf, ntohs(cp->dport),
1226 ip_vs_state_name(cp),
1227 ip_vs_origin_name(cp->flags),
1228 jiffies_delta_to_msecs(cp->timer.expires -
1235 ip_vs_proto_name(cp->protocol),
1236 ntohl(cp->caddr.ip), ntohs(cp->cport),
1237 ntohl(cp->vaddr.ip), ntohs(cp->vport),
1238 dbuf, ntohs(cp->dport),
1239 ip_vs_state_name(cp),
1240 ip_vs_origin_name(cp->flags),
1241 jiffies_delta_to_msecs(cp->timer.expires -
1262 static inline int todrop_entry(struct ip_vs_conn *cp)
1275 if (time_before(cp->timeout + jiffies, cp->timer.expires + 60*HZ))
1280 i = atomic_read(&cp->in_pkts);
1290 static inline bool ip_vs_conn_ops_mode(struct ip_vs_conn *cp)
1294 if (!cp->dest)
1296 svc = rcu_dereference(cp->dest->svc);
1304 struct ip_vs_conn *cp;
1313 hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[hash], c_list) {
1314 if (cp->ipvs != ipvs)
1316 if (atomic_read(&cp->n_control))
1318 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
1320 if (ip_vs_conn_ops_mode(cp))
1322 if (!(cp->state & IP_VS_CTPL_S_ASSURED))
1326 if (cp->protocol == IPPROTO_TCP) {
1327 switch(cp->state) {
1333 if (todrop_entry(cp))
1340 } else if (cp->protocol == IPPROTO_SCTP) {
1341 switch (cp->state) {
1346 if (todrop_entry(cp))
1354 if (!todrop_entry(cp))
1360 ip_vs_conn_del(cp);
1374 struct ip_vs_conn *cp, *cp_c;
1380 hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[idx], c_list) {
1381 if (cp->ipvs != ipvs)
1383 if (atomic_read(&cp->n_control))
1385 cp_c = cp->control;
1387 ip_vs_conn_del(cp);
1409 struct ip_vs_conn *cp, *cp_c;
1414 hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[idx], c_list) {
1415 if (cp->ipvs != ipvs)
1418 dest = cp->dest;
1422 if (atomic_read(&cp->n_control))
1425 cp_c = cp->control;
1427 ip_vs_conn_del(cp);