Dear Elmer,

thanks for the example. I actually added your callback to my init code,
and changed the subscription "type" to 18888, such that the example should
work fine with the tipc_demo-1.16/topology_subscr_demo/ example.

But it doesn't (2.6.24, on x86_64). Loading the module shows the messages are
sent fine, and a new connection is in the "tipc-config -p" output:
2818850801: connected to <1.1.178:2818850799>

But when I start the user-space subscriptions monitor from the
topology_subscr_demo the ports output shows something like:
2818850753: connected to <1.1.178:2818850751> via {1,1}
2818850751: connected to <1.1.178:2818850753>

So I'm missing one of the connections.

The user-space subscription monitor is reporting correctly publish/withdraw
events, e.g. when starting server_tipc from the demo. This tells me that
either I'm doing something really wrong, or something is broken with the
native interface in 2.6.24. If you want to try reproducing, the source is
attached.

Best regards,
Erich
#KSRC=/home/focht/Projects/kerrighed/linux-2.6.24-kddm
KSRC=/lib/modules/$(shell uname -r)/build

obj-m += subscr_monitor.o

all:
	make -C $(KSRC) M=$(PWD) modules

clean:
	make -C $(KSRC) M=$(PWD) clean
/*
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/uio.h>

#include <linux/tipc.h>
#include <net/tipc/tipc.h>

static u32 user_ref;

static void mon_conn_msg_event_cb(void *usr_handle,
                               u32 port_ref,
                               struct sk_buff **buf,
                               unsigned char const *data,
                               unsigned int size,
                               unsigned int importance, 
                               struct tipc_portid const *orig,
                               struct tipc_name_seq const *destination)
{
	struct tipc_event *event;   /* topology events subscription) */
	int res;                    /* result of an operation */
	int errno = 0;

	printk("received a message of %d bytes on port %d\n", size, port_ref);

	event = (struct tipc_event *)data;      /* point event to data */
	printk("received subscription event (event=%d)\n", event->event);
	if (event->event == TIPC_SUBSCR_TIMEOUT) {
		printk("Subscription timed out?? (was forever)\n");
		goto monitorExit;
        }
	if (event->event == TIPC_PUBLISHED) {
		printk("Subscription published\n");
        }
	if (event->event == TIPC_WITHDRAWN) {
		printk("Subscription withdrawn\n");
        }

	printk("mon_conn_msg_event_cb: event information:\n");
	printk("      event = %d, event lower=%d, upper=%d\n",
	       event->event,
	       event->found_lower, event->found_upper);
	printk("      portid.ref=%d, portid.node=0x%x\n",
	       event->port.ref,
	       event->port.node);
	return;

monitorExit:
    /* set global to stop this run */
	res = tipc_shutdown(port_ref);
	if (res) {
		printk("shutdown of port %d had result=%d (errno=%d)\n",
		       port_ref, res, errno);
        }
	res = tipc_deleteport(port_ref);
	if (res) {
		printk("deleteport of port %d had result=%d (errno=%d)\n",
		       port_ref, res, errno);
        }
	return;
}

static int __init subscr_monitor_init(void)
{
	struct tipc_subscr sub;
	struct tipc_name name;
	struct iovec zero_msg = {NULL, 0};
	struct iovec my_iov;
	u32 port_ref;
	int i, res;

	res = tipc_attach(&user_ref, NULL, NULL);
	if (res)
		return res;

	res = tipc_createport(user_ref, NULL, TIPC_LOW_IMPORTANCE,
			      NULL, NULL, NULL,
			      NULL, NULL,
			      (tipc_conn_msg_event) mon_conn_msg_event_cb,
			      NULL, &port_ref);
	if (res)
		return res;
	
	name.type = TIPC_TOP_SRV;
	name.instance = TIPC_TOP_SRV;

	res = tipc_send2name(port_ref, &name, 0, 1, &zero_msg);
	printk("tipc_send2name returned %d\n", res);

	sub.seq.type = 18888;
	sub.seq.lower = 1;
	sub.seq.upper = 2560000;
	sub.timeout = TIPC_WAIT_FOREVER;
	sub.filter = TIPC_SUB_PORTS;
	my_iov.iov_base = (char *)&sub;
	my_iov.iov_len = sizeof(sub);

	res = tipc_send(port_ref, 1, &my_iov);
	printk("tipc_send returned %d\n", res);

	return res;
}

static void __exit subscr_monitor_exit(void)
{
	tipc_detach(user_ref);
}

module_init(subscr_monitor_init);
module_exit(subscr_monitor_exit);

MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Erich Focht");
MODULE_DESCRIPTION("TIPC native subscription monitor");
MODULE_VERSION("1.0");

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
tipc-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tipc-discussion

Reply via email to