<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Evolution Systems &#187; Software Development</title>
	<atom:link href="http://evolution-systems.co.uk/category/matts-blog/software-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://evolution-systems.co.uk</link>
	<description>Web Development, Software Development and Linux Consultancy services</description>
	<lastBuildDate>Fri, 08 Aug 2025 09:18:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>FreeBSD TODO Lists</title>
		<link>http://evolution-systems.co.uk/2009/06/25/freebsd-todo-lists-2/</link>
		<comments>http://evolution-systems.co.uk/2009/06/25/freebsd-todo-lists-2/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 18:54:59 +0000</pubDate>
		<dc:creator><![CDATA[Matthew Jakeman]]></dc:creator>
				<category><![CDATA[Matts Blog]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[FreeBSD]]></category>

		<guid isPermaLink="false">http://evolution-systems.co.uk/wordpress/?p=478</guid>
		<description><![CDATA[I just spotted an email on the FreeBSD Hackers mailing list asking for small open source projects for a few students to partake in. Of more interest was one of the replies. It had a list of url&#8217;s for the FreeBSD TODO lists that I hadn&#8217;t seen before. So if anyone is looking to contribute [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I just spotted an email on the FreeBSD Hackers mailing list asking for small open source projects for a few students to partake in. Of more interest was one of the replies. It had a list of url&#8217;s for the FreeBSD TODO lists that I hadn&#8217;t seen before. So if anyone is looking to contribute to the FreeBSD project in any way this would be a good place to start. There are a number of different areas within which you can participate and the TODO lists are quite a nice way to break things down so people can easily spot areas where their expertise could be useful.</p>
<p>Anyway here is the list of url&#8217;s thanks to Joel Dahl over at FreeBSD:</p>
<p><a href="http://wiki.freebsd.org/Networking">Networking</a><br />
<a href="http://wiki.freebsd.org/IPv6TODO">IPv6</a><br />
<a href="http://wiki.freebsd.org/BsnmpTODO">Bsnmp</a><br />
<a href="http://wiki.freebsd.org/Jails">Jails</a><br />
<a href="http://wiki.freebsd.org/USBTODO">USB</a><br />
<a href="http://wiki.freebsd.org/SMPTODO">SMP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://evolution-systems.co.uk/2009/06/25/freebsd-todo-lists-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hash Table Implementation</title>
		<link>http://evolution-systems.co.uk/2009/06/12/hash-table-implementation-2/</link>
		<comments>http://evolution-systems.co.uk/2009/06/12/hash-table-implementation-2/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 00:28:47 +0000</pubDate>
		<dc:creator><![CDATA[Matthew Jakeman]]></dc:creator>
				<category><![CDATA[Matts Blog]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Hash Table]]></category>
		<category><![CDATA[Kernel]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://evolution-systems.co.uk/wordpress/?p=483</guid>
		<description><![CDATA[I have been doing some more kernel module coding and have been using the linked list implementation provided by list.h quite a bit recently as I have known in advance that the lists would only ever have a small amount of entries so looping through the list would not prove to be too much of [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I have been doing some more kernel module coding and have been using the linked list implementation provided by list.h quite a bit recently as I have known in advance that the lists would only ever have a small amount of entries so looping through the list would not prove to be too much of a performance penalty.</p>
<p>For my latest problem however I have a list that could grow a bit larger in size so I made the decision to use a hash table instead of a linked list. I searched through the kernel source naively hoping there would be a neat generic hash table implementation included.. Alas there is not.</p>
<p>After a bit of searching I stumbled across <a href="http://uthash.sourceforge.net/">uthash</a>. This is a nice hash table implementation allowing you to basically put any struct into a hash table based on using one of the fields in the struct as the id. The included macro&#8217;s allow a string or an int to be used for the id as well which is quite useful.</p>
<p>So far it seems quite simple to use. All the functions are included in one header file wrapped us as macro&#8217;s so it is nice and easy to integrate with any project and it doesn&#8217;t rely on much to be included externally. In my case all the functions it does need are provided by the kernel so it was very simple to integrate. I will definitely be using this again in other projects in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://evolution-systems.co.uk/2009/06/12/hash-table-implementation-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Sleeping Linux Kernel Thread</title>
		<link>http://evolution-systems.co.uk/2009/05/26/simple-sleeping-linux-kernel-thread-2/</link>
		<comments>http://evolution-systems.co.uk/2009/05/26/simple-sleeping-linux-kernel-thread-2/#comments</comments>
		<pubDate>Tue, 26 May 2009 12:56:35 +0000</pubDate>
		<dc:creator><![CDATA[Matthew Jakeman]]></dc:creator>
				<category><![CDATA[Matts Blog]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Kernel]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Sleep]]></category>
		<category><![CDATA[Thread]]></category>

		<guid isPermaLink="false">http://evolution-systems.co.uk/wordpress/?p=485</guid>
		<description><![CDATA[I am currently implementing the timeout functionality for the NP++ kernel module. Each physical mapping has a function pointer defined in its descriptive struct (struct np_sw) as described here. Until now this hasn&#8217;t actually been implemented but I wanted to create a kernel thread that simply sleeps for 500 milliseconds, then awakes and looks through [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I am currently implementing the timeout functionality for the NP++ kernel module. Each physical mapping has a function pointer defined in its descriptive struct (struct np_sw) as described <a href="http://wiki.mjakeman.co.uk/index.php?title=Implementing_An_NP%2B%2B_Mapping_Module_HOWTO">here</a>.</p>
<p>Until now this hasn&#8217;t actually been implemented but I wanted to create a kernel thread that simply sleeps for 500 milliseconds, then awakes and looks through all the physical mappings available on the system and calls their timeout function.</p>
<p>This is a fairly simple process but in order to achieve it we need to include a couple of new headers :</p>
<p><code>#include &lt;linux/kthread.h&gt;<br />#include &lt;linux/delay.h&gt;</code><br />
The first of these is for the thread related functions needed and the second is to allow us to sleep the thread.</p>
<p>Now we have those included we need to declare a function that will be called when we start the thread as follows :</p>
<p><code>int timeout_thread(void *data)</code><br />
Any kernel thread function needs ro return an int and take a void pointer as the only argument to conform with the function pointer defined the kthread_create() function in kthread.h which the kthread_run() macro is a wrapper for.</p>
<p>Now we need to actually create the thread. I have done this in the modules init_module() function as follows:</p>
<p><code>kthread_run(timeout_thread, NULL, "NP++ Timeout Thread");</code><br />
Now this is all done we simply need to put some implementation into the timeout_thread() function to perform the sleep as follows:</p>
<p><code>while(1)<br />{<br />  set_current_state(TASK_RUNNING);<br />  //Some Code Here<br />  set_current_state(TASK_INTERRUPTIBLE);<br />  msleep(500);<br />}</code><br />
This sets the state of the thread to TASK_RUNNING to tell the kernel that the thread is working. The code to call the mappings individual timeout functions will go here. Then we set the state to TASK_INTERRUPTIBLE to tell the kernel we aren&#8217;t doing anything at which point we call the msleep() function to sleep the thread for 500 milliseconds.</p>
<p>Compile the module and you have a nice thread that will run roughly every 500 milliseconds. If you need a longer delay that can be measured in seconds the delay.h header also defines the following function that takes the number of seconds as the only argument:</p>
<p><code>void ssleep(unsigned int seconds);</code></p>
]]></content:encoded>
			<wfw:commentRss>http://evolution-systems.co.uk/2009/05/26/simple-sleeping-linux-kernel-thread-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conditional Statements Explained</title>
		<link>http://evolution-systems.co.uk/2008/06/11/conditional-statements-explained-2/</link>
		<comments>http://evolution-systems.co.uk/2008/06/11/conditional-statements-explained-2/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 17:53:07 +0000</pubDate>
		<dc:creator><![CDATA[Matthew Jakeman]]></dc:creator>
				<category><![CDATA[Matts Blog]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Compilation]]></category>
		<category><![CDATA[Conditional]]></category>

		<guid isPermaLink="false">http://evolution-systems.co.uk/wordpress/?p=505</guid>
		<description><![CDATA[I have often used #if, #ifdef, #if defined() etc as conditional preprocessor directives but haven&#8217;t really thought in depth about the differences between them. It was only when someone asked the question in a C channel on freenode that it made me think. A quick search of google brought me across a nice little explanation. [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I have often used #if, #ifdef, #if defined() etc as conditional preprocessor directives but haven&#8217;t really thought in depth about the differences between them. It was only when someone asked the question in a C channel on freenode that it made me think.</p>
<p>A quick search of google brought me across a nice little explanation. Rather than recycling the information here is the link :</p>
<p><a href="http://docs.hp.com/en/B3901-90003/ch07s05.html">Conditional Compilation (#if, #ifdef, ..#endif)</a></p>
<p>Quite an interesting little read.</p>
]]></content:encoded>
			<wfw:commentRss>http://evolution-systems.co.uk/2008/06/11/conditional-statements-explained-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux XFRM Framework Selectors</title>
		<link>http://evolution-systems.co.uk/2008/04/17/linux-xfrm-framework-selectors-2/</link>
		<comments>http://evolution-systems.co.uk/2008/04/17/linux-xfrm-framework-selectors-2/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 14:21:34 +0000</pubDate>
		<dc:creator><![CDATA[Matthew Jakeman]]></dc:creator>
				<category><![CDATA[Matts Blog]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Selectors]]></category>
		<category><![CDATA[XFRM]]></category>

		<guid isPermaLink="false">http://evolution-systems.co.uk/wordpress/?p=507</guid>
		<description><![CDATA[Whilst progressing some code I have been writing I was recently introduced to Linux&#8217;s XFRM (transform) framework. I had not heard of this before but it can be a very useful tool for manipulating packets. The one big downside to XFRM is there is virtually no documentation on it yet. This can make working with [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Whilst progressing some code I have been writing I was recently introduced to Linux&#8217;s XFRM (transform) framework. I had not heard of this before but it can be a very useful tool for manipulating packets.</p>
<p>The one big downside to XFRM is there is virtually no documentation on it yet. This can make working with it quite tricky. I am documenting what I find out from using it here in the hope that others will find it useful.</p>
<p> The basic idea behind XFRM is that it allows you to select a packet based on a number of factors. These are all defined in /usr/include/linux/xfrm.h in a struct named xfrm_selector as defined below :</p>
<p><code>struct xfrm_selector<br />{<br />    xfrm_address_t  daddr;<br />    xfrm_address_t  saddr;<br />    __be16  dport;<br />    __be16  dport_mask;<br />    __be16  sport;<br />    __be16  sport_mask;<br />    __u16   family;<br />    __u8    prefixlen_d;<br />    __u8    prefixlen_s;<br />    __u8    proto;<br />    int ifindex;<br />    uid_t   user;<br />};</code><br />
Creating a struct of this type and setting the fields such as the source/destination addresses, ports, address masks etc, allows a packet to be selected, based on this criteria, to allow it to be transformed. By passing this information into the kernel using a nlmsghdr struct and the addattr_l() function along with a template (struct xfmr_user_tmpl) describing what action to take on the packet we can alter certain packets however we wish.</p>
<p>This is proving very useful to me in some of my current work and I will continue to post anything I think might be useful to others working in the same area on this blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://evolution-systems.co.uk/2008/04/17/linux-xfrm-framework-selectors-2/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Structure Packing in GCC</title>
		<link>http://evolution-systems.co.uk/2008/03/26/structure-packing-in-gcc-2/</link>
		<comments>http://evolution-systems.co.uk/2008/03/26/structure-packing-in-gcc-2/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 17:49:01 +0000</pubDate>
		<dc:creator><![CDATA[Matthew Jakeman]]></dc:creator>
				<category><![CDATA[Matts Blog]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Gcc]]></category>
		<category><![CDATA[Nemo]]></category>
		<category><![CDATA[Network Programming]]></category>
		<category><![CDATA[Structures]]></category>

		<guid isPermaLink="false">http://evolution-systems.co.uk/wordpress/?p=509</guid>
		<description><![CDATA[I have recently been doing a lot of coding using the NEPL NEMO Implementation as a part of a project I am working on. This has proved to be very interesting work and has brought about lots of interesting problems. One of the most recent problems I faced involved a packet I was sending over [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I have recently been doing a lot of coding using the <a href="http://nautilus6.org/nemo/index.php">NEPL NEMO Implementation</a> as a part of a project I am working on. This has proved to be very interesting work and has brought about lots of interesting problems.</p>
<p>One of the most recent problems I faced involved a packet I was sending over the network using a header I had constructed using a struct as follows.</p>
<p><code>struct Nino<br />{<br />  uint8_t type;<br />  uint8_t length;<br />  uint8_t prefix_len;<br />  uint8_t res_l_4;<br />  uint32_t nino_lifetime;<br />  uint32_t reserved2;<br />  uint8_t nino_depth;<br />  uint8_t reserved3;<br />  uint16_t nino_seq;<br />  struct in6_addr _prefix_in6_addr;<br />};</code><br />
This was the exact packet header format that I required but when I received a packet and checked it using a version of <a href="http://www.wireshark.org">Wireshark</a> I had modified to recognise the header format, I was getting what seemed like an erroneous 2 Bytes of data (set to 0&#8217;s) at the beginning of the in6_addr. This puzzled me for a while until I started to think about how GCC would lay out the fields in the struct. Of course GCC tries to optimise the struct for passing across the hardware and pads it if it feels it is necessary.</p>
<p>For my purposes this ruins the whole layout of the packet header for processing so I had a look around and found that GCC has an attribute named __packed__ that will force it not to pad the struct out. Or in the terms of the GCC Manual :<br />
<span class="tags">
<ul>
<li>&#8220;a variable or structure field should have the smallest possible alignment&#8211;one byte for a variable, and one bit for a field, unless you specify a larger value with the aligned attribute.&#8221;</li>
</ul>
<p></span>This was exactly what I wanted. So by changing the struct definition from that above, to :</p>
<p><code>struct Nino<br />{<br />  uint8_t type;<br />  uint8_t length;<br />  uint8_t prefix_len;<br />  uint8_t res_l_4;<br />  uint32_t nino_lifetime;<br />  uint32_t reserved2;<br />  uint8_t nino_depth;<br />  uint8_t reserved3;<br />  uint16_t nino_seq;<br />  struct in6_addr _prefix_in6_addr;<br />}__attribute__((__packed__));</code><br />
My code behaved exactly as I required. Problem solved. This is a handy little function of GCC especially when dealing with network packets to make sure you know exactly how the compiler is behaving and hence avoiding any unwanted surprised.</p>
<p>A slightly more in depth look at the packed attribute can be found <a href="http://sig9.com/articles/gcc-packed-structures">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://evolution-systems.co.uk/2008/03/26/structure-packing-in-gcc-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
