summerofcode2020projects:networkconfigurationlibraries

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
summerofcode2020projects:networkconfigurationlibraries [2020/06/07 21:59] – AhsanBarkatisummerofcode2020projects:networkconfigurationlibraries [2021/06/13 19:15] (current) – Formatting fix ChristosMargiolis
Line 1: Line 1:
 ====== Network Configuration Libraries ====== ====== Network Configuration Libraries ======
-  * Student: **[[/AhsanBarkati|Ahsan Barkati]]** (ahsanb@%%FreeBSD%%.org) +  * Student: [[/AhsanBarkati|AhsanBarkati]] (ahsanb@) 
-  * Mentors: +  * Mentors:  
-    * [[/KristofProvost|KristofProvost]] (kp@freebsd.org) +    * [[/KristofProvost|KristofProvost]] (kp@) 
-    * [[/TomJones|TomJones]] (thj@freebsd.org)+    * [[/TomJones|TomJones]] (thj@) 
 + 
 +===== The Code ===== 
 + 
 +https://github.com/ahsanbarkati/freebsd/tree/libroute/lib/libroute 
 + 
 +===== Revisions Submitted ===== 
 + 
 +^  Differential  ^  Title  ^  Status  ^ 
 +| [[https://reviews.freebsd.org/D25220|D25220]] | Add tests for "add", "change" and "delete" functionality of /sbin/route. | [[https://github.com/freebsd/freebsd/tree/36ae2ebd15f9e6f27f33bb672d25a3d9dd427792/sbin/route/tests|Merged]] ✔ | 
 +| [[https://reviews.freebsd.org/D26078|D26078]] | Add libroute and basic librarification of route utility | In Review |
  
 ===== Project description ===== ===== Project description =====
-%%FreeBSD%% has high quality tools for  management of the network, which includes tools to configure and manage interfaces, the firewalls and more. However these tools are not available as libraries, any software that wishes to incorporate network management must shell out to the command line tools. This limits the range of possible tools for automating control of a %%FreeBSD%% system. The aim of this project is to develop some of the  libraries which would enable the programmatic configuration/management of network interfaces, packet filtering and routing. An example use case of these libraries would be to enable a bhyve VM to be bridged to the host’s ethernet network programmatically and similar benefits can be harvested for the jails as well.+%%FreeBSD%% has high quality tools for  management of the network, which includes tools to configure and manage interfaces, the firewalls and more. However these tools are not available as libraries, any software that wishes to incorporate network management must shell out to the command line tools. This limits the range of possible tools for automating control of a %%FreeBSD%% system. The aim of this project is to develop libroute, a library with APIs to manage routes.
  
-===== Proposed Libraries =====+===== Libroute =====
  
-* libroute: The manual manipulation of the network routing tables is generally achieved by the /sbin/route utility. It provides functionality to add, flush, change, show the routes along with optional modifiers which enable setting some initial parameters to the routes such as RTT, MTU etc. This project aims to create a library which brings in a method to programmatically manage the routing. This library will allow addition of the routes to the FIB and also a method to change a particular route, delete a route or even flush the whole routing table. It is also intended that the library should be able to read the complete routing table of the system and hence simulate the netstat -r command line utility.+Manual manipulation of the network routing tables is generally achieved by the ''%%/sbin/route%%'' utility. It provides functionality to add, flush, change, show the routes along with optional modifiers which enable setting some initial parameters to the routes such as RTT, MTU etc. This project aims to create a library which brings in a method to programmatically manage the routing. This library will allow addition of the routes to the FIB and also a method to change a particular route, delete a route or even flush the whole routing table.
  
-* libipfw: Packet filtering is one of the major requirements in most of the network setups. For the purpose of VM and Jail management, NAT (Network Address Translation) functionality can be used to make the guest (VM or jail) connect to the internet, NATed via the Host. ipfw provides the NAT function and the /sbin/ipfw is the user interface for the firewall as well as the in-kernel NAT. The /lib/libipfw is intended to provide the functionalities so that the network managers could programmatically set rules in the ipfw firewall and set up NAT.+===== Status of libroute ===== 
 +The current status of the libroute library is as follows: 
 +  * It can be used to add, delete, change and get routes for both IPv4 and IPv6.  
 +  * There is a bug with the default route addition, I am currently looking into it. 
 +  * The man page for libroute can be found [[https://github.com/ahsanbarkati/freebsd/blob/libroute/lib/libroute/libroute.3|here]].
  
-===== Deliverables =====+The general design of libroute is primarily characterized by the use of a handle. The library provides a method to get a libroute handle (via the ''%%libroute_open()%%'' API) and all the functionalities of the library is accessed by making use of this handle. The handle stores the FIB number on which it will operate and the socket that it will use to communicate with the kernel. At any point of time, this FIB number can be modified using the ''%%libroute_setfib()%%'' API. At the end this handle needs to be closed and this will free the memory held by the handle. There are various functions that this library provides: 
 +  * ''%%libroute_modify()%%'' 
 +  * ''%%libroute_add()%%'' 
 +  * ''%%libroute_change()%%'' 
 +  * ''%%libroute_delete()%%'' 
 +  * ''%%libroute_get()%%''
  
-==== First Evaluation- ====+Example usage of library:
  
-* libroute containing the functionality of adding a route.+<code> 
 +#include <stdio.h> 
 +#include <libroute.h>
  
-* Make /sbin/route use the libroute for adding a route.+int 
 +main() 
 +{ 
 +        rt_handle *h; 
 + struct sockaddr *sa_dest, *sa_gateway; 
 + int defaultfib, error; 
 +  
 +        // get the default FIB number 
 +        size_t len = sizeof(defaultfib); 
 + sysctlbyname("net.my_fibnum", (void *)&defaultfib, &len, NULL,0);
  
-* Regression test for the route add functionality.+        // Open the libroute handle 
 + h = libroute_open(defaultfib); 
 + if (h == NULL) 
 + printf("failed to open handle\n");
  
-==== Second Evaluation- ==== + dest = "192.168.2.6"; 
-* libroute containing other functionalities such as flushing, deleting and changing a route.+ gateway = "172.16.2.1"; 
 +         
 +        // convert addresses to sockaddr structs 
 + sa_dest = str_to_sockaddr(dest); 
 + sa_gateway = str_to_sockaddr(gateway);
  
-* Make /sbin/route use libroute for the above functionalities.+        // add the new route 
 + error = libroute_add(h, sa_dest, sa_gateway); 
 +        if (error == -1 ) 
 +                printf("Failed to add route, error code is %d", libroute_geterr(h));
  
-* Regression tests for the above functionalities of route.+        libroute_close(h); 
 +  
 +        return (0); 
 +} 
 +</code>
  
-==== Final Evaluation- ==== +===== Test Plan =====
-* libipfw capable of setting up a NAT instance on the specified interface.+
  
-* libipfw capable of inserting packet filtering rules in the ipfw firewall.+Currently the testing of the library is not done directly, but it relies on the route utility for it. During this project, we have written tests for the route utility. The tests running on the librarified route indirectly tests the library. We have plans 
 +to add tests which directly tests the library.
  
-* Regression tests for the above functionalities of libipfw.+===== Future Work =====
  
-===== The Code =====+==== Bugs ==== 
 +  * Modification to default route is broken. 
 +  * Scope of buffer overflow in ''%%fill_so()%%'' function.
  
-https://github.com/ahsanbarkati/freebsd+==== Testing ==== 
 +  * A test suite for the library, written in C. 
  
 ===== Useful links ===== ===== Useful links =====
  • summerofcode2020projects/networkconfigurationlibraries.1591567175.txt.gz
  • Last modified: 2020/06/07 21:59
  • by AhsanBarkati