提交 65bd449c 编写于 作者: D David S. Miller

Merge branch 'tipc-de-generealize-topology-server'

Jon Maloy says:

====================
tipc: de-generealize topology server

The topology server is partially based on a template that is much
more generic than what we need. This results in a code that is
unnecessarily hard to follow and keeping bug free.

We now take the consequence of the fact that we only have one such
server in TIPC, - with no prospects for introducing any more, and
adapt the code to the specialized task is really is doing.
====================
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
...@@ -9,7 +9,7 @@ tipc-y += addr.o bcast.o bearer.o \ ...@@ -9,7 +9,7 @@ tipc-y += addr.o bcast.o bearer.o \
core.o link.o discover.o msg.o \ core.o link.o discover.o msg.o \
name_distr.o subscr.o monitor.o name_table.o net.o \ name_distr.o subscr.o monitor.o name_table.o net.o \
netlink.o netlink_compat.o node.o socket.o eth_media.o \ netlink.o netlink_compat.o node.o socket.o eth_media.o \
server.o socket.o group.o topsrv.o socket.o group.o
tipc-$(CONFIG_TIPC_MEDIA_UDP) += udp_media.o tipc-$(CONFIG_TIPC_MEDIA_UDP) += udp_media.o
tipc-$(CONFIG_TIPC_MEDIA_IB) += ib_media.o tipc-$(CONFIG_TIPC_MEDIA_IB) += ib_media.o
......
...@@ -64,7 +64,7 @@ struct tipc_bearer; ...@@ -64,7 +64,7 @@ struct tipc_bearer;
struct tipc_bc_base; struct tipc_bc_base;
struct tipc_link; struct tipc_link;
struct tipc_name_table; struct tipc_name_table;
struct tipc_server; struct tipc_topsrv;
struct tipc_monitor; struct tipc_monitor;
#define TIPC_MOD_VER "2.0.0" #define TIPC_MOD_VER "2.0.0"
...@@ -112,7 +112,7 @@ struct tipc_net { ...@@ -112,7 +112,7 @@ struct tipc_net {
struct list_head dist_queue; struct list_head dist_queue;
/* Topology subscription server */ /* Topology subscription server */
struct tipc_server *topsrv; struct tipc_topsrv *topsrv;
atomic_t subscription_count; atomic_t subscription_count;
}; };
...@@ -131,7 +131,7 @@ static inline struct list_head *tipc_nodes(struct net *net) ...@@ -131,7 +131,7 @@ static inline struct list_head *tipc_nodes(struct net *net)
return &tipc_net(net)->node_list; return &tipc_net(net)->node_list;
} }
static inline struct tipc_server *tipc_topsrv(struct net *net) static inline struct tipc_topsrv *tipc_topsrv(struct net *net)
{ {
return tipc_net(net)->topsrv; return tipc_net(net)->topsrv;
} }
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include "addr.h" #include "addr.h"
#include "group.h" #include "group.h"
#include "bcast.h" #include "bcast.h"
#include "server.h" #include "topsrv.h"
#include "msg.h" #include "msg.h"
#include "socket.h" #include "socket.h"
#include "node.h" #include "node.h"
......
...@@ -326,10 +326,10 @@ static struct publication *tipc_nameseq_insert_publ(struct net *net, ...@@ -326,10 +326,10 @@ static struct publication *tipc_nameseq_insert_publ(struct net *net,
/* Any subscriptions waiting for notification? */ /* Any subscriptions waiting for notification? */
list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) {
tipc_subscrp_report_overlap(s, publ->lower, publ->upper, tipc_sub_report_overlap(s, publ->lower, publ->upper,
TIPC_PUBLISHED, publ->ref, TIPC_PUBLISHED, publ->ref,
publ->node, publ->scope, publ->node, publ->scope,
created_subseq); created_subseq);
} }
return publ; return publ;
} }
...@@ -397,10 +397,9 @@ static struct publication *tipc_nameseq_remove_publ(struct net *net, ...@@ -397,10 +397,9 @@ static struct publication *tipc_nameseq_remove_publ(struct net *net,
/* Notify any waiting subscriptions */ /* Notify any waiting subscriptions */
list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) {
tipc_subscrp_report_overlap(s, publ->lower, publ->upper, tipc_sub_report_overlap(s, publ->lower, publ->upper,
TIPC_WITHDRAWN, publ->ref, TIPC_WITHDRAWN, publ->ref, publ->node,
publ->node, publ->scope, publ->scope, removed_subseq);
removed_subseq);
} }
return publ; return publ;
...@@ -412,33 +411,37 @@ static struct publication *tipc_nameseq_remove_publ(struct net *net, ...@@ -412,33 +411,37 @@ static struct publication *tipc_nameseq_remove_publ(struct net *net,
* sequence overlapping with the requested sequence * sequence overlapping with the requested sequence
*/ */
static void tipc_nameseq_subscribe(struct name_seq *nseq, static void tipc_nameseq_subscribe(struct name_seq *nseq,
struct tipc_subscription *s, struct tipc_subscription *sub)
bool status)
{ {
struct sub_seq *sseq = nseq->sseqs; struct sub_seq *sseq = nseq->sseqs;
struct tipc_name_seq ns; struct tipc_name_seq ns;
struct tipc_subscr *s = &sub->evt.s;
bool no_status;
tipc_subscrp_convert_seq(&s->evt.s.seq, s->swap, &ns); ns.type = tipc_sub_read(s, seq.type);
ns.lower = tipc_sub_read(s, seq.lower);
ns.upper = tipc_sub_read(s, seq.upper);
no_status = tipc_sub_read(s, filter) & TIPC_SUB_NO_STATUS;
tipc_subscrp_get(s); tipc_sub_get(sub);
list_add(&s->nameseq_list, &nseq->subscriptions); list_add(&sub->nameseq_list, &nseq->subscriptions);
if (!status || !sseq) if (no_status || !sseq)
return; return;
while (sseq != &nseq->sseqs[nseq->first_free]) { while (sseq != &nseq->sseqs[nseq->first_free]) {
if (tipc_subscrp_check_overlap(&ns, sseq->lower, sseq->upper)) { if (tipc_sub_check_overlap(&ns, sseq->lower, sseq->upper)) {
struct publication *crs; struct publication *crs;
struct name_info *info = sseq->info; struct name_info *info = sseq->info;
int must_report = 1; int must_report = 1;
list_for_each_entry(crs, &info->zone_list, zone_list) { list_for_each_entry(crs, &info->zone_list, zone_list) {
tipc_subscrp_report_overlap(s, sseq->lower, tipc_sub_report_overlap(sub, sseq->lower,
sseq->upper, sseq->upper,
TIPC_PUBLISHED, TIPC_PUBLISHED,
crs->ref, crs->node, crs->ref, crs->node,
crs->scope, crs->scope,
must_report); must_report);
must_report = 0; must_report = 0;
} }
} }
...@@ -808,24 +811,27 @@ int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 ref, ...@@ -808,24 +811,27 @@ int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 ref,
/** /**
* tipc_nametbl_subscribe - add a subscription object to the name table * tipc_nametbl_subscribe - add a subscription object to the name table
*/ */
void tipc_nametbl_subscribe(struct tipc_subscription *s, bool status) void tipc_nametbl_subscribe(struct tipc_subscription *sub)
{ {
struct tipc_net *tn = net_generic(s->net, tipc_net_id); struct tipc_net *tn = tipc_net(sub->net);
u32 type = tipc_subscrp_convert_seq_type(s->evt.s.seq.type, s->swap); struct tipc_subscr *s = &sub->evt.s;
u32 type = tipc_sub_read(s, seq.type);
int index = hash(type); int index = hash(type);
struct name_seq *seq; struct name_seq *seq;
struct tipc_name_seq ns; struct tipc_name_seq ns;
spin_lock_bh(&tn->nametbl_lock); spin_lock_bh(&tn->nametbl_lock);
seq = nametbl_find_seq(s->net, type); seq = nametbl_find_seq(sub->net, type);
if (!seq) if (!seq)
seq = tipc_nameseq_create(type, &tn->nametbl->seq_hlist[index]); seq = tipc_nameseq_create(type, &tn->nametbl->seq_hlist[index]);
if (seq) { if (seq) {
spin_lock_bh(&seq->lock); spin_lock_bh(&seq->lock);
tipc_nameseq_subscribe(seq, s, status); tipc_nameseq_subscribe(seq, sub);
spin_unlock_bh(&seq->lock); spin_unlock_bh(&seq->lock);
} else { } else {
tipc_subscrp_convert_seq(&s->evt.s.seq, s->swap, &ns); ns.type = tipc_sub_read(s, seq.type);
ns.lower = tipc_sub_read(s, seq.lower);
ns.upper = tipc_sub_read(s, seq.upper);
pr_warn("Failed to create subscription for {%u,%u,%u}\n", pr_warn("Failed to create subscription for {%u,%u,%u}\n",
ns.type, ns.lower, ns.upper); ns.type, ns.lower, ns.upper);
} }
...@@ -835,18 +841,19 @@ void tipc_nametbl_subscribe(struct tipc_subscription *s, bool status) ...@@ -835,18 +841,19 @@ void tipc_nametbl_subscribe(struct tipc_subscription *s, bool status)
/** /**
* tipc_nametbl_unsubscribe - remove a subscription object from name table * tipc_nametbl_unsubscribe - remove a subscription object from name table
*/ */
void tipc_nametbl_unsubscribe(struct tipc_subscription *s) void tipc_nametbl_unsubscribe(struct tipc_subscription *sub)
{ {
struct tipc_net *tn = net_generic(s->net, tipc_net_id); struct tipc_subscr *s = &sub->evt.s;
struct tipc_net *tn = tipc_net(sub->net);
struct name_seq *seq; struct name_seq *seq;
u32 type = tipc_subscrp_convert_seq_type(s->evt.s.seq.type, s->swap); u32 type = tipc_sub_read(s, seq.type);
spin_lock_bh(&tn->nametbl_lock); spin_lock_bh(&tn->nametbl_lock);
seq = nametbl_find_seq(s->net, type); seq = nametbl_find_seq(sub->net, type);
if (seq != NULL) { if (seq != NULL) {
spin_lock_bh(&seq->lock); spin_lock_bh(&seq->lock);
list_del_init(&s->nameseq_list); list_del_init(&sub->nameseq_list);
tipc_subscrp_put(s); tipc_sub_put(sub);
if (!seq->first_free && list_empty(&seq->subscriptions)) { if (!seq->first_free && list_empty(&seq->subscriptions)) {
hlist_del_init_rcu(&seq->ns_list); hlist_del_init_rcu(&seq->ns_list);
kfree(seq->sseqs); kfree(seq->sseqs);
......
...@@ -120,7 +120,7 @@ struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type, ...@@ -120,7 +120,7 @@ struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type,
struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type, struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type,
u32 lower, u32 node, u32 ref, u32 lower, u32 node, u32 ref,
u32 key); u32 key);
void tipc_nametbl_subscribe(struct tipc_subscription *s, bool status); void tipc_nametbl_subscribe(struct tipc_subscription *s);
void tipc_nametbl_unsubscribe(struct tipc_subscription *s); void tipc_nametbl_unsubscribe(struct tipc_subscription *s);
int tipc_nametbl_init(struct net *net); int tipc_nametbl_init(struct net *net);
void tipc_nametbl_stop(struct net *net); void tipc_nametbl_stop(struct net *net);
......
/* /*
* net/tipc/subscr.c: TIPC network topology service * net/tipc/subscr.c: TIPC network topology service
* *
* Copyright (c) 2000-2006, Ericsson AB * Copyright (c) 2000-2017, Ericsson AB
* Copyright (c) 2005-2007, 2010-2013, Wind River Systems * Copyright (c) 2005-2007, 2010-2013, Wind River Systems
* All rights reserved. * All rights reserved.
* *
...@@ -38,61 +38,30 @@ ...@@ -38,61 +38,30 @@
#include "name_table.h" #include "name_table.h"
#include "subscr.h" #include "subscr.h"
/** static void tipc_sub_send_event(struct tipc_subscription *sub,
* struct tipc_subscriber - TIPC network topology subscriber u32 found_lower, u32 found_upper,
* @kref: reference counter to tipc_subscription object u32 event, u32 port, u32 node)
* @conid: connection identifier to server connecting to subscriber
* @lock: control access to subscriber
* @subscrp_list: list of subscription objects for this subscriber
*/
struct tipc_subscriber {
struct kref kref;
int conid;
spinlock_t lock;
struct list_head subscrp_list;
};
static void tipc_subscrb_put(struct tipc_subscriber *subscriber);
/**
* htohl - convert value to endianness used by destination
* @in: value to convert
* @swap: non-zero if endianness must be reversed
*
* Returns converted value
*/
static u32 htohl(u32 in, int swap)
{
return swap ? swab32(in) : in;
}
static void tipc_subscrp_send_event(struct tipc_subscription *sub,
u32 found_lower, u32 found_upper,
u32 event, u32 port_ref, u32 node)
{ {
struct tipc_net *tn = net_generic(sub->net, tipc_net_id); struct tipc_event *evt = &sub->evt;
struct tipc_subscriber *subscriber = sub->subscriber;
struct kvec msg_sect;
msg_sect.iov_base = (void *)&sub->evt; if (sub->inactive)
msg_sect.iov_len = sizeof(struct tipc_event); return;
sub->evt.event = htohl(event, sub->swap); tipc_evt_write(evt, event, event);
sub->evt.found_lower = htohl(found_lower, sub->swap); tipc_evt_write(evt, found_lower, found_lower);
sub->evt.found_upper = htohl(found_upper, sub->swap); tipc_evt_write(evt, found_upper, found_upper);
sub->evt.port.ref = htohl(port_ref, sub->swap); tipc_evt_write(evt, port.ref, port);
sub->evt.port.node = htohl(node, sub->swap); tipc_evt_write(evt, port.node, node);
tipc_conn_sendmsg(tn->topsrv, subscriber->conid, NULL, tipc_topsrv_queue_evt(sub->net, sub->conid, event, evt);
msg_sect.iov_base, msg_sect.iov_len);
} }
/** /**
* tipc_subscrp_check_overlap - test for subscription overlap with the * tipc_sub_check_overlap - test for subscription overlap with the
* given values * given values
* *
* Returns 1 if there is overlap, otherwise 0. * Returns 1 if there is overlap, otherwise 0.
*/ */
int tipc_subscrp_check_overlap(struct tipc_name_seq *seq, u32 found_lower, int tipc_sub_check_overlap(struct tipc_name_seq *seq, u32 found_lower,
u32 found_upper) u32 found_upper)
{ {
if (found_lower < seq->lower) if (found_lower < seq->lower)
found_lower = seq->lower; found_lower = seq->lower;
...@@ -103,298 +72,98 @@ int tipc_subscrp_check_overlap(struct tipc_name_seq *seq, u32 found_lower, ...@@ -103,298 +72,98 @@ int tipc_subscrp_check_overlap(struct tipc_name_seq *seq, u32 found_lower,
return 1; return 1;
} }
u32 tipc_subscrp_convert_seq_type(u32 type, int swap) void tipc_sub_report_overlap(struct tipc_subscription *sub,
{ u32 found_lower, u32 found_upper,
return htohl(type, swap); u32 event, u32 port, u32 node,
} u32 scope, int must)
void tipc_subscrp_convert_seq(struct tipc_name_seq *in, int swap,
struct tipc_name_seq *out)
{
out->type = htohl(in->type, swap);
out->lower = htohl(in->lower, swap);
out->upper = htohl(in->upper, swap);
}
void tipc_subscrp_report_overlap(struct tipc_subscription *sub, u32 found_lower,
u32 found_upper, u32 event, u32 port_ref,
u32 node, u32 scope, int must)
{ {
u32 filter = htohl(sub->evt.s.filter, sub->swap); struct tipc_subscr *s = &sub->evt.s;
u32 filter = tipc_sub_read(s, filter);
struct tipc_name_seq seq; struct tipc_name_seq seq;
tipc_subscrp_convert_seq(&sub->evt.s.seq, sub->swap, &seq); seq.type = tipc_sub_read(s, seq.type);
if (!tipc_subscrp_check_overlap(&seq, found_lower, found_upper)) seq.lower = tipc_sub_read(s, seq.lower);
seq.upper = tipc_sub_read(s, seq.upper);
if (!tipc_sub_check_overlap(&seq, found_lower, found_upper))
return; return;
if (!must && !(filter & TIPC_SUB_PORTS)) if (!must && !(filter & TIPC_SUB_PORTS))
return; return;
if (filter & TIPC_SUB_CLUSTER_SCOPE && scope == TIPC_NODE_SCOPE) if (filter & TIPC_SUB_CLUSTER_SCOPE && scope == TIPC_NODE_SCOPE)
return; return;
if (filter & TIPC_SUB_NODE_SCOPE && scope != TIPC_NODE_SCOPE) if (filter & TIPC_SUB_NODE_SCOPE && scope != TIPC_NODE_SCOPE)
return; return;
spin_lock(&sub->lock);
tipc_subscrp_send_event(sub, found_lower, found_upper, event, port_ref, tipc_sub_send_event(sub, found_lower, found_upper,
node); event, port, node);
spin_unlock(&sub->lock);
} }
static void tipc_subscrp_timeout(struct timer_list *t) static void tipc_sub_timeout(struct timer_list *t)
{ {
struct tipc_subscription *sub = from_timer(sub, t, timer); struct tipc_subscription *sub = from_timer(sub, t, timer);
struct tipc_subscriber *subscriber = sub->subscriber; struct tipc_subscr *s = &sub->evt.s;
spin_lock_bh(&subscriber->lock);
tipc_nametbl_unsubscribe(sub);
list_del(&sub->subscrp_list);
spin_unlock_bh(&subscriber->lock);
/* Notify subscriber of timeout */
tipc_subscrp_send_event(sub, sub->evt.s.seq.lower, sub->evt.s.seq.upper,
TIPC_SUBSCR_TIMEOUT, 0, 0);
tipc_subscrp_put(sub);
}
static void tipc_subscrb_kref_release(struct kref *kref)
{
kfree(container_of(kref,struct tipc_subscriber, kref));
}
static void tipc_subscrb_put(struct tipc_subscriber *subscriber)
{
kref_put(&subscriber->kref, tipc_subscrb_kref_release);
}
static void tipc_subscrb_get(struct tipc_subscriber *subscriber) spin_lock(&sub->lock);
{ tipc_sub_send_event(sub, s->seq.lower, s->seq.upper,
kref_get(&subscriber->kref); TIPC_SUBSCR_TIMEOUT, 0, 0);
sub->inactive = true;
spin_unlock(&sub->lock);
} }
static void tipc_subscrp_kref_release(struct kref *kref) static void tipc_sub_kref_release(struct kref *kref)
{ {
struct tipc_subscription *sub = container_of(kref, kfree(container_of(kref, struct tipc_subscription, kref));
struct tipc_subscription,
kref);
struct tipc_net *tn = net_generic(sub->net, tipc_net_id);
struct tipc_subscriber *subscriber = sub->subscriber;
atomic_dec(&tn->subscription_count);
kfree(sub);
tipc_subscrb_put(subscriber);
} }
void tipc_subscrp_put(struct tipc_subscription *subscription) void tipc_sub_put(struct tipc_subscription *subscription)
{ {
kref_put(&subscription->kref, tipc_subscrp_kref_release); kref_put(&subscription->kref, tipc_sub_kref_release);
} }
void tipc_subscrp_get(struct tipc_subscription *subscription) void tipc_sub_get(struct tipc_subscription *subscription)
{ {
kref_get(&subscription->kref); kref_get(&subscription->kref);
} }
/* tipc_subscrb_subscrp_delete - delete a specific subscription or all struct tipc_subscription *tipc_sub_subscribe(struct net *net,
* subscriptions for a given subscriber. struct tipc_subscr *s,
*/ int conid)
static void tipc_subscrb_subscrp_delete(struct tipc_subscriber *subscriber,
struct tipc_subscr *s)
{
struct list_head *subscription_list = &subscriber->subscrp_list;
struct tipc_subscription *sub, *temp;
u32 timeout;
spin_lock_bh(&subscriber->lock);
list_for_each_entry_safe(sub, temp, subscription_list, subscrp_list) {
if (s && memcmp(s, &sub->evt.s, sizeof(struct tipc_subscr)))
continue;
timeout = htohl(sub->evt.s.timeout, sub->swap);
if (timeout == TIPC_WAIT_FOREVER || del_timer(&sub->timer)) {
tipc_nametbl_unsubscribe(sub);
list_del(&sub->subscrp_list);
tipc_subscrp_put(sub);
}
if (s)
break;
}
spin_unlock_bh(&subscriber->lock);
}
static struct tipc_subscriber *tipc_subscrb_create(int conid)
{
struct tipc_subscriber *subscriber;
subscriber = kzalloc(sizeof(*subscriber), GFP_ATOMIC);
if (!subscriber) {
pr_warn("Subscriber rejected, no memory\n");
return NULL;
}
INIT_LIST_HEAD(&subscriber->subscrp_list);
kref_init(&subscriber->kref);
subscriber->conid = conid;
spin_lock_init(&subscriber->lock);
return subscriber;
}
static void tipc_subscrb_delete(struct tipc_subscriber *subscriber)
{
tipc_subscrb_subscrp_delete(subscriber, NULL);
tipc_subscrb_put(subscriber);
}
static void tipc_subscrp_cancel(struct tipc_subscr *s,
struct tipc_subscriber *subscriber)
{
tipc_subscrb_get(subscriber);
tipc_subscrb_subscrp_delete(subscriber, s);
tipc_subscrb_put(subscriber);
}
static struct tipc_subscription *tipc_subscrp_create(struct net *net,
struct tipc_subscr *s,
int swap)
{ {
struct tipc_net *tn = net_generic(net, tipc_net_id); u32 filter = tipc_sub_read(s, filter);
struct tipc_subscription *sub; struct tipc_subscription *sub;
u32 filter = htohl(s->filter, swap); u32 timeout;
/* Refuse subscription if global limit exceeded */ if ((filter & TIPC_SUB_PORTS && filter & TIPC_SUB_SERVICE) ||
if (atomic_read(&tn->subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) { (tipc_sub_read(s, seq.lower) > tipc_sub_read(s, seq.upper))) {
pr_warn("Subscription rejected, limit reached (%u)\n", pr_warn("Subscription rejected, illegal request\n");
TIPC_MAX_SUBSCRIPTIONS);
return NULL; return NULL;
} }
/* Allocate subscription object */
sub = kmalloc(sizeof(*sub), GFP_ATOMIC); sub = kmalloc(sizeof(*sub), GFP_ATOMIC);
if (!sub) { if (!sub) {
pr_warn("Subscription rejected, no memory\n"); pr_warn("Subscription rejected, no memory\n");
return NULL; return NULL;
} }
/* Initialize subscription object */
sub->net = net; sub->net = net;
if (((filter & TIPC_SUB_PORTS) && (filter & TIPC_SUB_SERVICE)) || sub->conid = conid;
(htohl(s->seq.lower, swap) > htohl(s->seq.upper, swap))) { sub->inactive = false;
pr_warn("Subscription rejected, illegal request\n");
kfree(sub);
return NULL;
}
sub->swap = swap;
memcpy(&sub->evt.s, s, sizeof(*s)); memcpy(&sub->evt.s, s, sizeof(*s));
atomic_inc(&tn->subscription_count); spin_lock_init(&sub->lock);
kref_init(&sub->kref); kref_init(&sub->kref);
return sub; tipc_nametbl_subscribe(sub);
} timer_setup(&sub->timer, tipc_sub_timeout, 0);
timeout = tipc_sub_read(&sub->evt.s, timeout);
static int tipc_subscrp_subscribe(struct net *net, struct tipc_subscr *s,
struct tipc_subscriber *subscriber, int swap,
bool status)
{
struct tipc_subscription *sub = NULL;
u32 timeout;
sub = tipc_subscrp_create(net, s, swap);
if (!sub)
return -1;
spin_lock_bh(&subscriber->lock);
list_add(&sub->subscrp_list, &subscriber->subscrp_list);
sub->subscriber = subscriber;
tipc_nametbl_subscribe(sub, status);
tipc_subscrb_get(subscriber);
spin_unlock_bh(&subscriber->lock);
timer_setup(&sub->timer, tipc_subscrp_timeout, 0);
timeout = htohl(sub->evt.s.timeout, swap);
if (timeout != TIPC_WAIT_FOREVER) if (timeout != TIPC_WAIT_FOREVER)
mod_timer(&sub->timer, jiffies + msecs_to_jiffies(timeout)); mod_timer(&sub->timer, jiffies + msecs_to_jiffies(timeout));
return 0; return sub;
}
/* Handle one termination request for the subscriber */
static void tipc_subscrb_release_cb(int conid, void *usr_data)
{
tipc_subscrb_delete((struct tipc_subscriber *)usr_data);
}
/* Handle one request to create a new subscription for the subscriber */
static int tipc_subscrb_rcv_cb(struct net *net, int conid,
struct sockaddr_tipc *addr, void *usr_data,
void *buf, size_t len)
{
struct tipc_subscriber *subscriber = usr_data;
struct tipc_subscr *s = (struct tipc_subscr *)buf;
bool status;
int swap;
/* Determine subscriber's endianness */
swap = !(s->filter & (TIPC_SUB_PORTS | TIPC_SUB_SERVICE |
TIPC_SUB_CANCEL));
/* Detect & process a subscription cancellation request */
if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) {
s->filter &= ~htohl(TIPC_SUB_CANCEL, swap);
tipc_subscrp_cancel(s, subscriber);
return 0;
}
status = !(s->filter & htohl(TIPC_SUB_NO_STATUS, swap));
return tipc_subscrp_subscribe(net, s, subscriber, swap, status);
}
/* Handle one request to establish a new subscriber */
static void *tipc_subscrb_connect_cb(int conid)
{
return (void *)tipc_subscrb_create(conid);
}
int tipc_topsrv_start(struct net *net)
{
struct tipc_net *tn = net_generic(net, tipc_net_id);
const char name[] = "topology_server";
struct tipc_server *topsrv;
struct sockaddr_tipc *saddr;
saddr = kzalloc(sizeof(*saddr), GFP_ATOMIC);
if (!saddr)
return -ENOMEM;
saddr->family = AF_TIPC;
saddr->addrtype = TIPC_ADDR_NAMESEQ;
saddr->addr.nameseq.type = TIPC_TOP_SRV;
saddr->addr.nameseq.lower = TIPC_TOP_SRV;
saddr->addr.nameseq.upper = TIPC_TOP_SRV;
saddr->scope = TIPC_NODE_SCOPE;
topsrv = kzalloc(sizeof(*topsrv), GFP_ATOMIC);
if (!topsrv) {
kfree(saddr);
return -ENOMEM;
}
topsrv->net = net;
topsrv->saddr = saddr;
topsrv->imp = TIPC_CRITICAL_IMPORTANCE;
topsrv->type = SOCK_SEQPACKET;
topsrv->max_rcvbuf_size = sizeof(struct tipc_subscr);
topsrv->tipc_conn_recvmsg = tipc_subscrb_rcv_cb;
topsrv->tipc_conn_new = tipc_subscrb_connect_cb;
topsrv->tipc_conn_release = tipc_subscrb_release_cb;
strncpy(topsrv->name, name, strlen(name) + 1);
tn->topsrv = topsrv;
atomic_set(&tn->subscription_count, 0);
return tipc_server_start(topsrv);
} }
void tipc_topsrv_stop(struct net *net) void tipc_sub_unsubscribe(struct tipc_subscription *sub)
{ {
struct tipc_net *tn = net_generic(net, tipc_net_id); tipc_nametbl_unsubscribe(sub);
struct tipc_server *topsrv = tn->topsrv; if (sub->evt.s.timeout != TIPC_WAIT_FOREVER)
del_timer_sync(&sub->timer);
tipc_server_stop(topsrv); list_del(&sub->sub_list);
kfree(topsrv->saddr); tipc_sub_put(sub);
kfree(topsrv);
} }
/* /*
* net/tipc/subscr.h: Include file for TIPC network topology service * net/tipc/subscr.h: Include file for TIPC network topology service
* *
* Copyright (c) 2003-2006, Ericsson AB * Copyright (c) 2003-2017, Ericsson AB
* Copyright (c) 2005-2007, 2012-2013, Wind River Systems * Copyright (c) 2005-2007, 2012-2013, Wind River Systems
* All rights reserved. * All rights reserved.
* *
...@@ -37,48 +37,72 @@ ...@@ -37,48 +37,72 @@
#ifndef _TIPC_SUBSCR_H #ifndef _TIPC_SUBSCR_H
#define _TIPC_SUBSCR_H #define _TIPC_SUBSCR_H
#include "server.h" #include "topsrv.h"
#define TIPC_MAX_SUBSCRIPTIONS 65535 #define TIPC_MAX_SUBSCR 65535
#define TIPC_MAX_PUBLICATIONS 65535 #define TIPC_MAX_PUBLICATIONS 65535
struct tipc_subscription; struct tipc_subscription;
struct tipc_subscriber; struct tipc_conn;
/** /**
* struct tipc_subscription - TIPC network topology subscription object * struct tipc_subscription - TIPC network topology subscription object
* @subscriber: pointer to its subscriber * @subscriber: pointer to its subscriber
* @seq: name sequence associated with subscription * @seq: name sequence associated with subscription
* @net: point to network namespace
* @timer: timer governing subscription duration (optional) * @timer: timer governing subscription duration (optional)
* @nameseq_list: adjacent subscriptions in name sequence's subscription list * @nameseq_list: adjacent subscriptions in name sequence's subscription list
* @subscrp_list: adjacent subscriptions in subscriber's subscription list * @sub_list: adjacent subscriptions in subscriber's subscription list
* @swap: indicates if subscriber uses opposite endianness in its messages
* @evt: template for events generated by subscription * @evt: template for events generated by subscription
*/ */
struct tipc_subscription { struct tipc_subscription {
struct kref kref; struct kref kref;
struct tipc_subscriber *subscriber;
struct net *net; struct net *net;
struct timer_list timer; struct timer_list timer;
struct list_head nameseq_list; struct list_head nameseq_list;
struct list_head subscrp_list; struct list_head sub_list;
int swap;
struct tipc_event evt; struct tipc_event evt;
int conid;
bool inactive;
spinlock_t lock; /* serialize up/down and timer events */
}; };
int tipc_subscrp_check_overlap(struct tipc_name_seq *seq, u32 found_lower, struct tipc_subscription *tipc_sub_subscribe(struct net *net,
u32 found_upper); struct tipc_subscr *s,
void tipc_subscrp_report_overlap(struct tipc_subscription *sub, int conid);
u32 found_lower, u32 found_upper, u32 event, void tipc_sub_unsubscribe(struct tipc_subscription *sub);
u32 port_ref, u32 node, u32 scope, int must);
void tipc_subscrp_convert_seq(struct tipc_name_seq *in, int swap, int tipc_sub_check_overlap(struct tipc_name_seq *seq, u32 found_lower,
struct tipc_name_seq *out); u32 found_upper);
u32 tipc_subscrp_convert_seq_type(u32 type, int swap); void tipc_sub_report_overlap(struct tipc_subscription *sub,
u32 found_lower, u32 found_upper,
u32 event, u32 port, u32 node,
u32 scope, int must);
int tipc_topsrv_start(struct net *net); int tipc_topsrv_start(struct net *net);
void tipc_topsrv_stop(struct net *net); void tipc_topsrv_stop(struct net *net);
void tipc_subscrp_put(struct tipc_subscription *subscription); void tipc_sub_put(struct tipc_subscription *subscription);
void tipc_subscrp_get(struct tipc_subscription *subscription); void tipc_sub_get(struct tipc_subscription *subscription);
#define TIPC_FILTER_MASK (TIPC_SUB_PORTS | TIPC_SUB_SERVICE | TIPC_SUB_CANCEL)
/* tipc_sub_read - return field_ of struct sub_ in host endian format
*/
#define tipc_sub_read(sub_, field_) \
({ \
struct tipc_subscr *sub__ = sub_; \
u32 val__ = (sub__)->field_; \
int swap_ = !((sub__)->filter & TIPC_FILTER_MASK); \
(swap_ ? swab32(val__) : val__); \
})
/* tipc_evt_write - write val_ to field_ of struct evt_ in user endian format
*/
#define tipc_evt_write(evt_, field_, val_) \
({ \
struct tipc_event *evt__ = evt_; \
u32 val__ = val_; \
int swap_ = !((evt__)->s.filter & (TIPC_FILTER_MASK)); \
(evt__)->field_ = swap_ ? swab32(val__) : val__; \
})
#endif #endif
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* net/tipc/server.h: Include file for TIPC server code * net/tipc/server.h: Include file for TIPC server code
* *
* Copyright (c) 2012-2013, Wind River Systems * Copyright (c) 2012-2013, Wind River Systems
* Copyright (c) 2017, Ericsson AB
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
...@@ -36,68 +37,18 @@ ...@@ -36,68 +37,18 @@
#ifndef _TIPC_SERVER_H #ifndef _TIPC_SERVER_H
#define _TIPC_SERVER_H #define _TIPC_SERVER_H
#include <linux/idr.h> #include "core.h"
#include <linux/tipc.h>
#include <net/net_namespace.h>
#define TIPC_SERVER_NAME_LEN 32 #define TIPC_SERVER_NAME_LEN 32
#define TIPC_SUB_CLUSTER_SCOPE 0x20 #define TIPC_SUB_CLUSTER_SCOPE 0x20
#define TIPC_SUB_NODE_SCOPE 0x40 #define TIPC_SUB_NODE_SCOPE 0x40
#define TIPC_SUB_NO_STATUS 0x80 #define TIPC_SUB_NO_STATUS 0x80
/** void tipc_topsrv_queue_evt(struct net *net, int conid,
* struct tipc_server - TIPC server structure u32 event, struct tipc_event *evt);
* @conn_idr: identifier set of connection
* @idr_lock: protect the connection identifier set
* @idr_in_use: amount of allocated identifier entry
* @net: network namspace instance
* @rcvbuf_cache: memory cache of server receive buffer
* @rcv_wq: receive workqueue
* @send_wq: send workqueue
* @max_rcvbuf_size: maximum permitted receive message length
* @tipc_conn_new: callback will be called when new connection is incoming
* @tipc_conn_release: callback will be called before releasing the connection
* @tipc_conn_recvmsg: callback will be called when message arrives
* @saddr: TIPC server address
* @name: server name
* @imp: message importance
* @type: socket type
*/
struct tipc_server {
struct idr conn_idr;
spinlock_t idr_lock;
int idr_in_use;
struct net *net;
struct kmem_cache *rcvbuf_cache;
struct workqueue_struct *rcv_wq;
struct workqueue_struct *send_wq;
int max_rcvbuf_size;
void *(*tipc_conn_new)(int conid);
void (*tipc_conn_release)(int conid, void *usr_data);
int (*tipc_conn_recvmsg)(struct net *net, int conid,
struct sockaddr_tipc *addr, void *usr_data,
void *buf, size_t len);
struct sockaddr_tipc *saddr;
char name[TIPC_SERVER_NAME_LEN];
int imp;
int type;
};
int tipc_conn_sendmsg(struct tipc_server *s, int conid,
struct sockaddr_tipc *addr, void *data, size_t len);
bool tipc_topsrv_kern_subscr(struct net *net, u32 port, u32 type, u32 lower, bool tipc_topsrv_kern_subscr(struct net *net, u32 port, u32 type, u32 lower,
u32 upper, u32 filter, int *conid); u32 upper, u32 filter, int *conid);
void tipc_topsrv_kern_unsubscr(struct net *net, int conid); void tipc_topsrv_kern_unsubscr(struct net *net, int conid);
/**
* tipc_conn_terminate - terminate connection with server
*
* Note: Must call it in process context since it might sleep
*/
void tipc_conn_terminate(struct tipc_server *s, int conid);
int tipc_server_start(struct tipc_server *s);
void tipc_server_stop(struct tipc_server *s);
#endif #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册