Hi Evgeniy,
[snip]
>> 2. Isn't passing all arguments even for delete a bit... unconvenient?
>> Woulnd't be better to have two levels of indexes?
>
> Well, hard to tell. Usually the more indexes we have the more we want
> since there will be something we did not use in the previous ones.
> Having a full parameter list simplifies searching, but may look not
> that conveneint though.
I see your point, even if in this case it would be just one level more.
On the other hand finally I remember that neither iptables indexes while
deleting rules are "so" convenient.
The eternal struggle of the mankind against interfaces.
> Thanks for the patches. They look good, but are reversed and do not
> match some codying style issues used to be used in kernel like space and
> braces placement.
Unfortunately I can't spot wrong spaces and braces placement.
Indent man reports for kernel code:
-nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -d0 -di1
-nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai -saf -saw -ncs -nsc -sob
-nfca -cp33 -ss -ts8 -il1
which breaks lines shorter than 80 chars and use a different indentation
for switch/case and labels, which is not what you do, so it generates a
garbage patch.
Do you use some indent configuration to conform to kernel code style?
> Please also provide signed-off line as described in
> Documentation/SubmittingPatches
Included.
Best regards,
Pierpaolo
--- pohmelfs-server/cfg/cfg.c 2009-08-05 14:50:37.000000000 +0300
+++ pohmelfs-server.y/cfg/cfg.c 2009-08-05 14:49:18.000000000 +0300
@@ -53,12 +53,15 @@ static unsigned int pohmelfs_seq;
static void pohmelfs_display_function(struct pohmelfs_ctl *ctl)
{
static int display_banner;
+ static unsigned int last_config_index;
struct sockaddr_in *sa;
struct sockaddr_in6 *sa6;
struct in6_addr *in6;
struct sockaddr *saddr;
char inet6_addr[128];
+ if (last_config_index != ctl->idx) display_banner = 0;
+
if (!display_banner) {
printf("Config Index = %d\n", ctl->idx);
printf("Family Server IP
Port \n");
@@ -138,7 +141,7 @@ static int pohmelfs_recv_ack(int s, unsi
errno = ack->error;
if(errno)
return errno;
- if (flags == POHMELFS_FLAGS_SHOW) {
+ if (flags == POHMELFS_FLAGS_SHOW ||
POHMELFS_FLAGS_DUMP) {
pohmelfs_display_function(&ack->ctl);
}
if (!ack->msg_num)
@@ -252,6 +255,29 @@ static int pohmelfs_show_remote(int s, u
return err;
}
+static int pohmelfs_dump_remote(int s)
+{
+ struct pohmelfs_ctl ctl;
+ int err;
+ memset(&ctl, 0, sizeof(struct pohmelfs_ctl));
+ err = pohmelfs_netlink_send(s, POHMELFS_FLAGS_DUMP,
+ &ctl, sizeof(struct pohmelfs_ctl));
+
+ return err;
+}
+
+static int pohmelfs_flush_remote(int s, unsigned int idx)
+{
+ struct pohmelfs_ctl ctl;
+ int err;
+ memset(&ctl, 0, sizeof(struct pohmelfs_ctl));
+ ctl.idx = idx;
+ err = pohmelfs_netlink_send(s, POHMELFS_FLAGS_FLUSH,
+ &ctl, sizeof(struct pohmelfs_ctl));
+
+ return err;
+}
+
static int pohmelfs_add_remote(int s, char *addr, int port, unsigned int idx,
int perm, int prio, int action)
{
int err;
@@ -302,20 +328,21 @@ static int pohmelfs_add_crypto(int s, ch
static void pohmelfs_usage(char *p)
{
- fprintf(stderr, "Usage: %s -A[ction] {add/del/show/modify} -a[ddress]
{ipv4/ipv6} -p[ort] -i[ndex]"
+ fprintf(stderr, "Usage: %s -A[ction] {add/del/show/modify/dump/flush}
-a[ddress] {ipv4/ipv6} -p[ort] -i[ndex]"
" -k[cipher_key_file] -K [hash_key_file] -C[ipher] -H[ash]
-P[riority] -I[nput/output permissions] -h\n", p);
+ fprintf(stderr, "\tindex %d reserved as null idx\n", POHMELFS_NULL_IDX);
}
int main(int argc, char *argv[])
{
int ch, port, err, s, prio, perm;
- unsigned int idx;
+ int idx;
char *addr, *action, *cipher_key, *hash_key, *cipher, *hash;
struct sockaddr_nl l_local;
addr = NULL;
port = -1;
- idx = 0;
+ idx = POHMELFS_NULL_IDX;
action = cipher_key = hash_key = cipher = hash = NULL;
perm = POHMELFS_IO_PERM_READ | POHMELFS_IO_PERM_WRITE;
prio = 0;
@@ -334,6 +361,11 @@ int main(int argc, char *argv[])
prio = atoi(optarg);
break;
case 'i':
+ if(atoi(optarg) == POHMELFS_NULL_IDX)
+ {
+ pohmelfs_usage(argv[0]);
+ return -1;
+ }
idx = atoi(optarg);
break;
case 'C':
@@ -390,6 +422,11 @@ int main(int argc, char *argv[])
err = -EINVAL;
if (action) {
+ if (strncmp(action, "flush", 5)) {
+ if(idx == -1)
+ idx = 0;
+ }
+
if (!strncmp(action, "add", 3)) {
if (addr && port != -1)
err = pohmelfs_add_remote(s, addr, port, idx,
perm, prio, POHMELFS_FLAGS_ADD);
@@ -419,6 +456,14 @@ int main(int argc, char *argv[])
if (err)
goto out;
}
+ } else if (!strncmp(action, "dump", 4)) {
+ err = pohmelfs_dump_remote(s);
+ if (err)
+ goto out;
+ } else if (!strncmp(action, "flush", 5)) {
+ err = pohmelfs_flush_remote(s, idx);
+ if (err)
+ goto out;
} else if (!strncmp(action, "modify", 6)) {
err = pohmelfs_add_remote(s, addr, port, idx, perm,
prio, POHMELFS_FLAGS_MODIFY);
if (err)
Signed-off-by: Pierpaolo Giacomin <[email protected]>
diff -uprN -X linux-2.6.30.4.ori/Documentation/dontdiff
linux-2.6.30.4.ori/drivers/staging/pohmelfs/config.c
linux-2.6.30.4/drivers/staging/pohmelfs/config.c
--- linux-2.6.30.4.ori/drivers/staging/pohmelfs/config.c 2009-08-11
20:48:06.000000000 +0300
+++ linux-2.6.30.4/drivers/staging/pohmelfs/config.c 2009-08-11
20:53:22.000000000 +0300
@@ -38,9 +38,9 @@ static DEFINE_MUTEX(pohmelfs_config_lock
static inline int pohmelfs_config_eql(struct pohmelfs_ctl *sc, struct
pohmelfs_ctl *ctl)
{
if (sc->idx == ctl->idx && sc->type == ctl->type &&
- sc->proto == ctl->proto &&
- sc->addrlen == ctl->addrlen &&
- !memcmp(&sc->addr, &ctl->addr, ctl->addrlen))
+ sc->proto == ctl->proto &&
+ sc->addrlen == ctl->addrlen &&
+ !memcmp(&sc->addr, &ctl->addr, ctl->addrlen))
return 1;
return 0;
@@ -284,9 +284,91 @@ static int pohmelfs_cn_disp(struct cn_ms
i += 1;
}
+ out_unlock:
+ mutex_unlock(&pohmelfs_config_lock);
+ return err;
+}
+
+static int pohmelfs_cn_dump(struct cn_msg *msg)
+{
+ struct pohmelfs_config_group *g;
+ struct pohmelfs_config *c, *tmp;
+ int err = 0, i = 1;
+ int total_msg = 0;
+
+ if (msg->len != sizeof(struct pohmelfs_ctl))
+ return -EBADMSG;
+
+ mutex_lock(&pohmelfs_config_lock);
+
+ list_for_each_entry(g, &pohmelfs_config_list, group_entry) {
+ if (g)
+ total_msg += g->num_entry;
+ }
+ if (total_msg == 0) {
+ if (pohmelfs_send_reply(err, 0, POHMELFS_NOINFO_ACK, msg, NULL))
+ err = -ENOMEM;
+ goto out_unlock;
+ }
+
+ list_for_each_entry(g, &pohmelfs_config_list, group_entry) {
+ if (g) {
+ list_for_each_entry_safe(c, tmp, &g->config_list,
config_entry) {
+ struct pohmelfs_ctl *sc = &c->state.ctl;
+ if (pohmelfs_send_reply(err, total_msg - i,
POHMELFS_CTLINFO_ACK, msg, sc)) {
+ err = -ENOMEM;
+ goto out_unlock;
+ }
+ i += 1;
+ }
+ }
+ }
+
out_unlock:
- mutex_unlock(&pohmelfs_config_lock);
- return err;
+ mutex_unlock(&pohmelfs_config_lock);
+ return err;
+}
+
+static int pohmelfs_cn_flush(struct cn_msg *msg)
+{
+ struct pohmelfs_config_group *g;
+ struct pohmelfs_ctl *ctl = (struct pohmelfs_ctl *)msg->data;
+ struct pohmelfs_config *c, *tmp;
+ int err = 0;
+
+ if (msg->len != sizeof(struct pohmelfs_ctl))
+ return -EBADMSG;
+
+ mutex_lock(&pohmelfs_config_lock);
+
+ if (ctl->idx != POHMELFS_NULL_IDX) {
+ g = pohmelfs_find_config_group(ctl->idx);
+
+ if (!g) {
+ goto out_unlock;
+ }
+ list_for_each_entry_safe(c, tmp, &g->config_list, config_entry)
{
+ list_del(&c->config_entry);
+ g->num_entry--;
+ kfree(c);
+ }
+ } else {
+ list_for_each_entry(g, &pohmelfs_config_list, group_entry) {
+ if (g) {
+ list_for_each_entry_safe(c, tmp,
&g->config_list, config_entry) {
+ list_del(&c->config_entry);
+ g->num_entry--;
+ kfree(c);
+ }
+ }
+ }
+ }
+
+out_unlock:
+ mutex_unlock(&pohmelfs_config_lock);
+ pohmelfs_cn_dump(msg);
+
+ return err;
}
static int pohmelfs_modify_config(struct pohmelfs_ctl *old, struct
pohmelfs_ctl *new)
@@ -350,7 +432,7 @@ static int pohmelfs_cn_ctl(struct cn_msg
list_add_tail(&c->config_entry, &g->config_list);
-out_unlock:
+ out_unlock:
mutex_unlock(&pohmelfs_config_lock);
if (pohmelfs_send_reply(err, 0, POHMELFS_NOINFO_ACK, msg, NULL))
err = -ENOMEM;
@@ -408,7 +490,6 @@ static int pohmelfs_crypto_cipher_init(s
return 0;
}
-
static int pohmelfs_cn_crypto(struct cn_msg *msg)
{
struct pohmelfs_crypto *crypto = (struct pohmelfs_crypto *)msg->data;
@@ -457,9 +538,15 @@ static void pohmelfs_cn_callback(void *d
case POHMELFS_FLAGS_MODIFY:
err = pohmelfs_cn_ctl(msg, msg->flags);
break;
+ case POHMELFS_FLAGS_FLUSH:
+ err = pohmelfs_cn_flush(msg);
+ break;
case POHMELFS_FLAGS_SHOW:
err = pohmelfs_cn_disp(msg);
break;
+ case POHMELFS_FLAGS_DUMP:
+ err = pohmelfs_cn_dump(msg);
+ break;
case POHMELFS_FLAGS_CRYPTO:
err = pohmelfs_cn_crypto(msg);
break;
diff -uprN -X linux-2.6.30.4.ori/Documentation/dontdiff
linux-2.6.30.4.ori/drivers/staging/pohmelfs/netfs.h
linux-2.6.30.4/drivers/staging/pohmelfs/netfs.h
--- linux-2.6.30.4.ori/drivers/staging/pohmelfs/netfs.h 2009-07-31
01:34:47.000000000 +0300
+++ linux-2.6.30.4/drivers/staging/pohmelfs/netfs.h 2009-08-05
13:13:43.000000000 +0300
@@ -25,6 +25,7 @@
#define POHMELFS_CTLINFO_ACK 1
#define POHMELFS_NOINFO_ACK 2
+#define POHMELFS_NULL_IDX 65535
/*
* Network command structure.
@@ -88,6 +89,8 @@ enum {
POHMELFS_FLAGS_SHOW, /* Network state control message for SHOW */
POHMELFS_FLAGS_CRYPTO, /* Crypto data control message */
POHMELFS_FLAGS_MODIFY, /* Network state modification message */
+ POHMELFS_FLAGS_DUMP, /* Network state control message for SHOW ALL */
+ POHMELFS_FLAGS_FLUSH, /* Network state control message for FLUSH */
};
/*
Signed-off-by: Pierpaolo Giacomin <[email protected]>
_______________________________________________
Pohmelfs mailing list
[email protected]
http://www.ioremap.net/cgi-bin/mailman/listinfo/pohmelfs