Skip to contentSkip to conversation

Ulogd - mysql addresses are in network-byte order

DISCUSSION marty 2 participants 3 messages Jan 2, 2012 netfilter

lore
Share & tools
lore

marty

author
#0 lore raw

Here, for your review is a patch to
address the issue that I reported.

ulogd_raw2packet_BASE.c renamed from orig.ulogd_raw2packet_BASE.c +2 -2
@@ -717,8 +717,8 @@
 		return ULOGD_IRET_OK;
 	len -= iph->ihl * 4;
 
-	okey_set_u32(&ret[KEY_IP_SADDR], iph->saddr);
-	okey_set_u32(&ret[KEY_IP_DADDR], iph->daddr);
+	okey_set_u32(&ret[KEY_IP_SADDR], ntohl(iph->saddr));
+	okey_set_u32(&ret[KEY_IP_DADDR], ntohl(iph->daddr));
 	okey_set_u8(&ret[KEY_IP_PROTOCOL], iph->protocol);
 	okey_set_u8(&ret[KEY_IP_TOS], iph->tos);
 	okey_set_u8(&ret[KEY_IP_TTL], iph->ttl);

Marty B.

#1 lore raw
Quoted 7 lines · marty

Here, for your review is a patch to
address the issue that I reported.

ulogd_raw2packet_BASE.c line 724

Quoted 10 lines
ulogd_raw2packet_BASE.c renamed from orig.ulogd_raw2packet_BASE.c +2 -2
@@ -717,8 +717,8 @@
 		return ULOGD_IRET_OK;
 	len -= iph->ihl * 4;
 
-	okey_set_u32(&ret[KEY_IP_SADDR], iph->saddr);
-	okey_set_u32(&ret[KEY_IP_DADDR], iph->daddr);
+	okey_set_u32(&ret[KEY_IP_SADDR], ntohl(iph->saddr));
+	okey_set_u32(&ret[KEY_IP_DADDR], ntohl(iph->daddr));
 	okey_set_u8(&ret[KEY_IP_PROTOCOL], iph->protocol);
 	okey_set_u8(&ret[KEY_IP_TOS], iph->tos);
 	okey_set_u8(&ret[KEY_IP_TTL], iph->ttl);

Many other plugins rely on the address in network byte order.

Can you fix this in the mysql plugin by adding some configurable option?

more suggestions for your next patches, please:

* include short description before the patch.
* they have to apply with patch -p1 < file.patch

you can generate this with git diff HEAD (there are more advanced ways to do this in git though).

thanks.

author
#2 lore raw
Quoted 21 lines · Pablo Neira Ayuso
Quoted 7 lines · marty

Here, for your review is a patch to
address the issue that I reported.

ulogd_raw2packet_BASE.c line 724

Quoted 10 lines
ulogd_raw2packet_BASE.c renamed from orig.ulogd_raw2packet_BASE.c +2 -2
@@ -717,8 +717,8 @@
  		return ULOGD_IRET_OK;
  	len -= iph->ihl * 4;
 
-	okey_set_u32(&ret[KEY_IP_SADDR], iph->saddr);
-	okey_set_u32(&ret[KEY_IP_DADDR], iph->daddr);
+	okey_set_u32(&ret[KEY_IP_SADDR], ntohl(iph->saddr));
+	okey_set_u32(&ret[KEY_IP_DADDR], ntohl(iph->daddr));
  	okey_set_u8(&ret[KEY_IP_PROTOCOL], iph->protocol);
  	okey_set_u8(&ret[KEY_IP_TOS], iph->tos);
  	okey_set_u8(&ret[KEY_IP_TTL], iph->ttl);

Many other plugins rely on the address in network byte order.

Quoted 2 lines

Can you fix this in the mysql plugin by adding some configurable option?

Seems like I already offered config options previously, no... And as I recall I gave fair warning, which you ignored. Simply put the host arch should determine IP format. That is a given. That is easily changed to network format where/when required.

Personally I would write the BASE code as I have, and let the option for network byte order be available as a config option, as I suggested from the start.

The mysql-plugin does not have the keys available directly. It pretty much passes data blindly.
I am hesitant to change this because it works nice.

Quoted 4 lines

more suggestions for your next patches, please:

* include short description before the patch.
* they have to apply with patch -p1< file.patch

Agreed, I should submit patches with more info.

Quoted 2 lines

you can generate this with git diff HEAD (there are more advanced ways to do this in git though)

Yes, I can do lots of things; even stand on my head.
But I fixed the issue as requested and if that is not sufficient I am terribly sorry, but I am a 60+ yr old man with a big schedule. The code works fine for my purposes and you are not inspiring me.

Marty B.