Move some setup functions from os_routing to os_net
authorHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Mon, 6 May 2013 07:10:59 +0000 (09:10 +0200)
committerHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Mon, 6 May 2013 07:10:59 +0000 (09:10 +0200)
files/Planned Dependencies.graphml
src-api/core/olsr_interface.c
src-api/core/olsr_interface.h
src-api/core/os_linux/os_net_linux.c
src-api/core/os_linux/os_routing_linux.c
src-api/core/os_net.h
src-api/core/os_routing.h

index 2b2bab8..6b7f947 100644 (file)
@@ -17,7 +17,7 @@
     <node id="n0">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="272.5" y="210.0"/>
+          <y:Geometry height="30.0" width="100.0" x="95.0" y="-375.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="33.7890625" x="33.10546875" y="6.015625">class<y:LabelModel>
@@ -34,7 +34,7 @@
     <node id="n1">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="549.2857142857143" y="60.0"/>
+          <y:Geometry height="30.0" width="100.0" x="290.0" y="-525.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="34.8203125" x="32.58984375" y="6.015625">clock<y:LabelModel>
@@ -51,7 +51,7 @@
     <node id="n2">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="622.5" y="510.0"/>
+          <y:Geometry height="30.0" width="100.0" x="300.0" y="-105.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="87.6484375" x="6.17578125" y="6.015625">packet socket<y:LabelModel>
@@ -68,7 +68,7 @@
     <node id="n3">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="614.2857142857143" y="210.0"/>
+          <y:Geometry height="30.0" width="100.0" x="380.0" y="-375.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="43.228515625" x="28.3857421875" y="6.015625">socket<y:LabelModel>
@@ -85,7 +85,7 @@
     <node id="n4">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="417.5" y="285.0"/>
+          <y:Geometry height="30.0" width="100.0" x="185.0" y="-285.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="89.359375" x="5.3203125" y="6.015625">stream socket<y:LabelModel>
     <node id="n5">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="549.2857142857143" y="120.0"/>
+          <y:Geometry height="30.0" width="100.0" x="290.0" y="-465.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="36.044921875" x="31.9775390625" y="6.015625">timer<y:LabelModel>
     <node id="n6">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="130.0" y="0.0"/>
+          <y:Geometry height="30.0" width="100.0" x="290.0" y="-585.0"/>
           <y:Fill color="#FFCC00" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="54.4140625" x="22.79296875" y="6.015625">os_clock<y:LabelModel>
     <node id="n7">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="585.0" y="360.0"/>
+          <y:Geometry height="30.0" width="100.0" x="405.0" y="-165.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="66.736328125" x="16.6318359375" y="6.015625">os_routing<y:LabelModel>
     <node id="n8">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="0.0" y="0.0"/>
+          <y:Geometry height="30.0" width="100.0" x="568.3333333333334" y="-585.0"/>
           <y:Fill color="#FFCC00" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="61.4921875" x="19.25390625" y="6.015625">os_syslog<y:LabelModel>
     <node id="n9">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="50.0" y="210.0"/>
+          <y:Geometry height="30.0" width="100.0" x="575.0" y="-375.0"/>
           <y:Fill color="#FFCC00" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="22.439453125" x="38.7802734375" y="6.015625">cfg<y:LabelModel>
     <node id="n10">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="25.0" y="60.0"/>
+          <y:Geometry height="30.0" width="100.0" x="543.3333333333334" y="-525.0"/>
           <y:Fill color="#FFCC00" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="48.466796875" x="25.7666015625" y="6.015625">logging<y:LabelModel>
     <node id="n11">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="25.0" y="120.0"/>
+          <y:Geometry height="30.0" width="100.0" x="608.3333333333334" y="-465.0"/>
           <y:Fill color="#FFCC00" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="47.365234375" x="26.3173828125" y="6.015625">plugins<y:LabelModel>
     <node id="n12">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="195.0" y="285.0"/>
+          <y:Geometry height="30.0" width="100.0" x="55.0" y="-285.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="81.701171875" x="9.1494140625" y="6.015625">duplicate set<y:LabelModel>
     <node id="n13">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="325.0" y="360.0"/>
+          <y:Geometry height="30.0" width="100.0" x="15.0" y="-165.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="28.6328125" x="35.68359375" y="6.015625">http<y:LabelModel>
     <node id="n14">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="12.5" y="285.0"/>
+          <y:Geometry height="30.0" width="100.0" x="550.0" y="-285.0"/>
           <y:Fill color="#FFCC00" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="70.720703125" x="14.6396484375" y="6.015625">logging cfg<y:LabelModel>
     <node id="n15">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="441.25" y="585.0"/>
+          <y:Geometry height="30.0" width="100.0" x="190.0" y="-30.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="50.294921875" x="24.8525390625" y="6.015625">rfc5444<y:LabelModel>
     <node id="n16">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="455.0" y="360.0"/>
+          <y:Geometry height="30.0" width="100.0" x="145.0" y="-165.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="39.115234375" x="30.4423828125" y="6.015625">telnet<y:LabelModel>
     <node id="n17">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="597.5" y="450.0"/>
+          <y:Geometry height="30.0" width="100.0" x="275.0" y="-165.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="57.51953125" x="21.240234375" y="6.015625">interface<y:LabelModel>
     <node id="n18">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="470.0" y="210.0"/>
+          <y:Geometry height="30.0" width="100.0" x="225.0" y="-375.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="43.287109375" x="28.3564453125" y="6.015625">os_net<y:LabelModel>
     <node id="n19">
       <data key="d6">
         <y:ShapeNode>
-          <y:Geometry height="30.0" width="100.0" x="614.2857142857143" y="285.0"/>
+          <y:Geometry height="30.0" width="100.0" x="380.0" y="-285.0"/>
           <y:Fill color="#00CCFF" transparent="false"/>
           <y:BorderStyle color="#000000" type="line" width="1.0"/>
           <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="66.9765625" x="16.51171875" y="6.015625">os_system<y:LabelModel>
     <edge id="e0" source="n9" target="n10">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="25.0" sy="-15.0" tx="33.33333333333333" ty="15.0">
-            <y:Point x="125.0" y="195.0"/>
-            <y:Point x="140.0" y="195.0"/>
-            <y:Point x="140.0" y="105.0"/>
-            <y:Point x="108.33333333333333" y="105.0"/>
+          <y:Path sx="-25.0" sy="-15.0" tx="0.0" ty="15.0">
+            <y:Point x="600.0" y="-390.0"/>
+            <y:Point x="593.3333333333334" y="-390.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
     <edge id="e1" source="n9" target="n11">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="-25.0" sy="-15.0" tx="0.0" ty="15.0"/>
+          <y:Path sx="25.0" sy="-15.0" tx="0.0" ty="15.0">
+            <y:Point x="650.0" y="-390.0"/>
+            <y:Point x="658.3333333333334" y="-390.0"/>
+          </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
           <y:BendStyle smoothed="false"/>
     <edge id="e2" source="n11" target="n10">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="0.0" sy="-15.0" tx="0.0" ty="15.0"/>
+          <y:Path sx="0.0" sy="-15.0" tx="33.33333333333333" ty="15.0">
+            <y:Point x="658.3333333333334" y="-480.0"/>
+            <y:Point x="626.6666666666667" y="-480.0"/>
+          </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
           <y:BendStyle smoothed="false"/>
     <edge id="e3" source="n17" target="n5">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="37.5" sy="-15.0" tx="28.571428571428555" ty="15.0">
-            <y:Point x="685.0" y="435.0"/>
-            <y:Point x="744.2857142857143" y="435.0"/>
-            <y:Point x="744.2857142857143" y="180.0"/>
-            <y:Point x="627.8571428571429" y="180.0"/>
+          <y:Path sx="0.0" sy="-15.0" tx="14.285714285714278" ty="15.0">
+            <y:Point x="325.0" y="-195.0"/>
+            <y:Point x="354.2857142857143" y="-195.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
     <edge id="e4" source="n17" target="n18">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="-37.5" sy="-15.0" tx="25.0" ty="15.0">
-            <y:Point x="610.0" y="435.0"/>
-            <y:Point x="570.0" y="435.0"/>
-            <y:Point x="570.0" y="285.0"/>
-            <y:Point x="545.0" y="285.0"/>
+          <y:Path sx="-33.333333333333314" sy="-15.0" tx="25.0" ty="15.0">
+            <y:Point x="291.6666666666667" y="-180.0"/>
+            <y:Point x="300.0" y="-180.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
     <edge id="e5" source="n17" target="n19">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="12.5" sy="-15.0" tx="25.0" ty="15.0">
-            <y:Point x="660.0" y="405.0"/>
-            <y:Point x="700.0" y="405.0"/>
-            <y:Point x="700.0" y="345.0"/>
-            <y:Point x="689.2857142857143" y="345.0"/>
+          <y:Path sx="33.33333333333333" sy="-15.0" tx="-25.0" ty="15.0">
+            <y:Point x="358.3333333333333" y="-180.0"/>
+            <y:Point x="405.0" y="-180.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e6" source="n17" target="n7">
-      <data key="d10">
-        <y:PolyLineEdge>
-          <y:Path sx="-12.5" sy="-15.0" tx="0.0" ty="15.0"/>
-          <y:LineStyle color="#000000" type="line" width="1.0"/>
-          <y:Arrows source="none" target="standard"/>
-          <y:BendStyle smoothed="false"/>
-        </y:PolyLineEdge>
-      </data>
-    </edge>
-    <edge id="e7" source="n10" target="n6">
+    <edge id="e6" source="n10" target="n6">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="25.0" sy="-15.0" tx="-33.33333333333333" ty="15.0">
-            <y:Point x="100.0" y="45.0"/>
-            <y:Point x="146.66666666666669" y="45.0"/>
+          <y:Path sx="-25.0" sy="-15.0" tx="33.33333333333333" ty="15.0">
+            <y:Point x="568.3333333333334" y="-540.0"/>
+            <y:Point x="373.3333333333333" y="-540.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e8" source="n10" target="n8">
+    <edge id="e7" source="n10" target="n8">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="-25.0" sy="-15.0" tx="0.0" ty="15.0"/>
+          <y:Path sx="25.0" sy="-15.0" tx="0.0" ty="15.0"/>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
           <y:BendStyle smoothed="false"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e9" source="n2" target="n17">
+    <edge id="e8" source="n2" target="n17">
       <data key="d10">
         <y:PolyLineEdge>
           <y:Path sx="-25.0" sy="-15.0" tx="0.0" ty="15.0"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e10" source="n2" target="n3">
+    <edge id="e9" source="n2" target="n3">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="25.0" sy="-15.0" tx="33.33333333333337" ty="15.0">
-            <y:Point x="697.5" y="495.0"/>
-            <y:Point x="712.5" y="495.0"/>
-            <y:Point x="712.5" y="420.0"/>
-            <y:Point x="729.2857142857143" y="420.0"/>
-            <y:Point x="729.2857142857143" y="270.0"/>
-            <y:Point x="697.6190476190477" y="270.0"/>
+          <y:Path sx="25.0" sy="-15.0" tx="33.333333333333314" ty="15.0">
+            <y:Point x="375.0" y="-120.0"/>
+            <y:Point x="520.0" y="-120.0"/>
+            <y:Point x="520.0" y="-300.0"/>
+            <y:Point x="463.3333333333333" y="-300.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e11" source="n3" target="n5">
+    <edge id="e10" source="n3" target="n5">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="0.0" sy="-15.0" tx="14.285714285714278" ty="15.0">
-            <y:Point x="664.2857142857143" y="195.0"/>
-            <y:Point x="613.5714285714287" y="195.0"/>
+          <y:Path sx="0.0" sy="-15.0" tx="28.571428571428555" ty="15.0">
+            <y:Point x="430.0" y="-390.0"/>
+            <y:Point x="368.57142857142856" y="-390.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e12" source="n4" target="n0">
+    <edge id="e11" source="n4" target="n0">
       <data key="d10">
         <y:PolyLineEdge>
           <y:Path sx="-37.5" sy="-15.0" tx="37.5" ty="15.0">
-            <y:Point x="430.0" y="270.0"/>
-            <y:Point x="360.0" y="270.0"/>
+            <y:Point x="197.5" y="-315.0"/>
+            <y:Point x="182.5" y="-315.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e13" source="n4" target="n3">
+    <edge id="e12" source="n4" target="n3">
       <data key="d10">
         <y:PolyLineEdge>
           <y:Path sx="37.5" sy="-15.0" tx="-33.33333333333333" ty="15.0">
-            <y:Point x="505.0" y="270.0"/>
-            <y:Point x="630.952380952381" y="270.0"/>
+            <y:Point x="272.5" y="-300.0"/>
+            <y:Point x="396.6666666666667" y="-300.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e14" source="n4" target="n5">
+    <edge id="e13" source="n4" target="n5">
       <data key="d10">
         <y:PolyLineEdge>
           <y:Path sx="-12.5" sy="-15.0" tx="-28.571428571428555" ty="15.0">
-            <y:Point x="455.0" y="195.0"/>
-            <y:Point x="570.7142857142858" y="195.0"/>
+            <y:Point x="222.5" y="-330.0"/>
+            <y:Point x="210.0" y="-330.0"/>
+            <y:Point x="210.0" y="-405.0"/>
+            <y:Point x="311.42857142857144" y="-405.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e15" source="n4" target="n18">
+    <edge id="e14" source="n4" target="n18">
       <data key="d10">
         <y:PolyLineEdge>
           <y:Path sx="12.5" sy="-15.0" tx="-25.0" ty="15.0">
-            <y:Point x="480.0" y="255.0"/>
-            <y:Point x="495.0" y="255.0"/>
+            <y:Point x="247.5" y="-300.0"/>
+            <y:Point x="250.0" y="-300.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e16" source="n5" target="n1">
+    <edge id="e15" source="n5" target="n1">
       <data key="d10">
         <y:PolyLineEdge>
           <y:Path sx="0.0" sy="-15.0" tx="0.0" ty="15.0"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e17" source="n1" target="n6">
+    <edge id="e16" source="n1" target="n6">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="0.0" sy="-15.0" tx="33.33333333333333" ty="15.0">
-            <y:Point x="599.2857142857143" y="45.0"/>
-            <y:Point x="213.33333333333331" y="45.0"/>
-          </y:Path>
+          <y:Path sx="0.0" sy="-15.0" tx="0.0" ty="15.0"/>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
           <y:BendStyle smoothed="false"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e18" source="n7" target="n5">
+    <edge id="e17" source="n7" target="n19">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="-25.0" sy="-15.0" tx="0.0" ty="15.0">
-            <y:Point x="610.0" y="345.0"/>
-            <y:Point x="599.2857142857143" y="345.0"/>
-          </y:Path>
+          <y:Path sx="0.0" sy="-15.0" tx="25.0" ty="15.0"/>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
           <y:BendStyle smoothed="false"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e19" source="n7" target="n19">
+    <edge id="e18" source="n19" target="n3">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="25.0" sy="-15.0" tx="-25.0" ty="15.0">
-            <y:Point x="660.0" y="345.0"/>
-            <y:Point x="639.2857142857143" y="345.0"/>
-          </y:Path>
+          <y:Path sx="0.0" sy="-15.0" tx="0.0" ty="15.0"/>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
           <y:BendStyle smoothed="false"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e20" source="n19" target="n3">
+    <edge id="e19" source="n12" target="n5">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="0.0" sy="-15.0" tx="0.0" ty="15.0"/>
+          <y:Path sx="-25.0" sy="-15.0" tx="-42.85714285714283" ty="15.0">
+            <y:Point x="80.0" y="-420.0"/>
+            <y:Point x="297.14285714285717" y="-420.0"/>
+          </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
           <y:BendStyle smoothed="false"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e21" source="n12" target="n5">
+    <edge id="e20" source="n12" target="n0">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="-25.0" sy="-15.0" tx="-42.85714285714289" ty="15.0">
-            <y:Point x="220.0" y="180.0"/>
-            <y:Point x="556.4285714285714" y="180.0"/>
+          <y:Path sx="25.0" sy="-15.0" tx="-12.5" ty="15.0">
+            <y:Point x="130.0" y="-300.0"/>
+            <y:Point x="132.5" y="-300.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e22" source="n12" target="n0">
+    <edge id="e21" source="n13" target="n4">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="25.0" sy="-15.0" tx="-37.5" ty="15.0">
-            <y:Point x="270.0" y="270.0"/>
-            <y:Point x="285.0" y="270.0"/>
+          <y:Path sx="25.0" sy="-15.0" tx="-25.0" ty="15.0">
+            <y:Point x="90.0" y="-240.0"/>
+            <y:Point x="210.0" y="-240.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e23" source="n13" target="n4">
+    <edge id="e22" source="n13" target="n6">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="25.0" sy="-15.0" tx="-25.0" ty="15.0">
-            <y:Point x="400.0" y="345.0"/>
-            <y:Point x="442.5" y="345.0"/>
+          <y:Path sx="-25.0" sy="-15.0" tx="-33.333333333333314" ty="15.0">
+            <y:Point x="40.0" y="-540.0"/>
+            <y:Point x="306.6666666666667" y="-540.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e24" source="n13" target="n6">
+    <edge id="e23" source="n14" target="n10">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="-25.0" sy="-15.0" tx="0.0" ty="15.0">
-            <y:Point x="350.0" y="345.0"/>
-            <y:Point x="180.0" y="345.0"/>
+          <y:Path sx="-25.0" sy="-15.0" tx="-33.33333333333337" ty="15.0">
+            <y:Point x="575.0" y="-300.0"/>
+            <y:Point x="560.0" y="-300.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e25" source="n14" target="n10">
+    <edge id="e24" source="n14" target="n9">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="-25.0" sy="-15.0" tx="-33.33333333333333" ty="15.0">
-            <y:Point x="37.5" y="270.0"/>
-            <y:Point x="10.0" y="270.0"/>
-            <y:Point x="10.0" y="105.0"/>
-            <y:Point x="41.66666666666667" y="105.0"/>
-          </y:Path>
+          <y:Path sx="25.0" sy="-15.0" tx="0.0" ty="15.0"/>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
           <y:BendStyle smoothed="false"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e26" source="n14" target="n9">
+    <edge id="e25" source="n15" target="n0">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="25.0" sy="-15.0" tx="0.0" ty="15.0">
-            <y:Point x="87.5" y="270.0"/>
-            <y:Point x="100.0" y="270.0"/>
+          <y:Path sx="-37.5" sy="-15.0" tx="-37.5" ty="15.0">
+            <y:Point x="202.5" y="-45.0"/>
+            <y:Point x="0.0" y="-45.0"/>
+            <y:Point x="0.0" y="-300.0"/>
+            <y:Point x="107.5" y="-300.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e27" source="n15" target="n0">
+    <edge id="e26" source="n15" target="n5">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="-12.5" sy="-15.0" tx="-12.5" ty="15.0">
-            <y:Point x="478.75" y="555.0"/>
-            <y:Point x="310.0" y="555.0"/>
+          <y:Path sx="37.5" sy="-15.0" tx="42.85714285714283" ty="15.0">
+            <y:Point x="277.5" y="-45.0"/>
+            <y:Point x="535.0" y="-45.0"/>
+            <y:Point x="535.0" y="-405.0"/>
+            <y:Point x="382.85714285714283" y="-405.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e28" source="n15" target="n5">
+    <edge id="e27" source="n16" target="n0">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="37.5" sy="-15.0" tx="42.857142857142776" ty="15.0">
-            <y:Point x="528.75" y="570.0"/>
-            <y:Point x="758.5714285714286" y="570.0"/>
-            <y:Point x="758.5714285714286" y="165.0"/>
-            <y:Point x="642.1428571428571" y="165.0"/>
+          <y:Path sx="-33.333333333333314" sy="-15.0" tx="12.5" ty="15.0">
+            <y:Point x="161.66666666666669" y="-180.0"/>
+            <y:Point x="170.0" y="-180.0"/>
+            <y:Point x="170.0" y="-300.0"/>
+            <y:Point x="157.5" y="-300.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e29" source="n16" target="n0">
+    <edge id="e28" source="n16" target="n4">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="-33.333333333333314" sy="-15.0" tx="12.5" ty="15.0">
-            <y:Point x="471.6666666666667" y="330.0"/>
-            <y:Point x="335.0" y="330.0"/>
+          <y:Path sx="0.0" sy="-15.0" tx="25.0" ty="15.0">
+            <y:Point x="195.0" y="-225.0"/>
+            <y:Point x="260.0" y="-225.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e30" source="n16" target="n4">
+    <edge id="e29" source="n16" target="n5">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="0.0" sy="-15.0" tx="25.0" ty="15.0">
-            <y:Point x="505.0" y="345.0"/>
-            <y:Point x="492.5" y="345.0"/>
+          <y:Path sx="33.333333333333314" sy="-15.0" tx="0.0" ty="15.0">
+            <y:Point x="228.33333333333331" y="-210.0"/>
+            <y:Point x="340.0" y="-210.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e31" source="n16" target="n5">
+    <edge id="e30" source="n15" target="n12">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="33.33333333333337" sy="-15.0" tx="-14.285714285714334" ty="15.0">
-            <y:Point x="538.3333333333334" y="345.0"/>
-            <y:Point x="585.0" y="345.0"/>
+          <y:Path sx="-12.5" sy="-15.0" tx="0.0" ty="15.0">
+            <y:Point x="227.5" y="-60.0"/>
+            <y:Point x="130.0" y="-60.0"/>
+            <y:Point x="130.0" y="-180.0"/>
+            <y:Point x="105.0" y="-180.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e32" source="n15" target="n12">
+    <edge id="e31" source="n15" target="n2">
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="-37.5" sy="-15.0" tx="0.0" ty="15.0">
-            <y:Point x="453.75" y="570.0"/>
-            <y:Point x="245.0" y="570.0"/>
+          <y:Path sx="12.5" sy="-15.0" tx="0.0" ty="15.0">
+            <y:Point x="252.5" y="-60.0"/>
+            <y:Point x="350.0" y="-60.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
         </y:PolyLineEdge>
       </data>
     </edge>
-    <edge id="e33" source="n15" target="n2">
+    <edge id="e32" source="n18" target="n5">
+      <data key="d9"/>
       <data key="d10">
         <y:PolyLineEdge>
-          <y:Path sx="12.5" sy="-15.0" tx="0.0" ty="15.0">
-            <y:Point x="503.75" y="555.0"/>
-            <y:Point x="672.5" y="555.0"/>
+          <y:Path sx="0.0" sy="-15.0" tx="-14.285714285714292" ty="15.0">
+            <y:Point x="275.0" y="-390.0"/>
+            <y:Point x="325.7142857142857" y="-390.0"/>
           </y:Path>
           <y:LineStyle color="#000000" type="line" width="1.0"/>
           <y:Arrows source="none" target="standard"/>
index 07eaf14..cbeb219 100644 (file)
@@ -54,7 +54,6 @@
 #include "core/olsr_subsystem.h"
 #include "core/os_net.h"
 #include "core/os_system.h"
-#include "core/os_routing.h"
 
 /* timeinterval to delay change in interface to trigger actions */
 #define OLSR_INTERFACE_CHANGE_INTERVAL 100
@@ -268,7 +267,7 @@ _interface_add(const char *name, bool mesh) {
   interf->usage_counter++;
   if(mesh) {
     if (interf->mesh_counter == 0) {
-      os_routing_init_mesh_if(interf);
+      os_net_init_mesh_if(interf);
     }
     interf->mesh_counter++;
   }
@@ -299,7 +298,7 @@ _interface_remove(struct olsr_interface *interf, bool mesh) {
 
     if (interf->mesh_counter < 1) {
       /* no mesh interface anymore, remove routing settings */
-      os_routing_cleanup_mesh_if(interf);
+      os_net_cleanup_mesh_if(interf);
     }
   }
 
index dea4a68..b55b9fa 100644 (file)
 #include "core/olsr_timer.h"
 #include "core/os_net.h"
 
-struct olsr_interface {
-  /* data of interface */
-  struct olsr_interface_data data;
-
-  /*
-   * usage counter to allow multiple instances to add the same
-   * interface
-   */
-  int usage_counter;
-
-  /*
-   * usage counter to keep track of the number of users on
-   * this interface who want to send mesh traffic
-   */
-  int mesh_counter;
-
-  /*
-   * used to store internal state of interfaces before
-   * configuring them for manet data forwarding.
-   * Only used by os_specific code.
-   */
-  uint32_t _original_state;
-
-  /* hook interfaces into tree */
-  struct avl_node _node;
-
-  /* timer for lazy interface change handling */
-  struct olsr_timer_entry _change_timer;
-};
-
 struct olsr_interface_listener {
   /* name of interface */
   const char *name;
index 4b192f2..c17169e 100644 (file)
 #include <net/if.h>
 #include <netinet/in.h>
 #include <sys/ioctl.h>
+#include <sys/utsname.h>
 #include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
 
 #include "common/common_types.h"
 
-#include "core/olsr_interface.h"
 #include "core/olsr_logging.h"
 #include "core/olsr_subsystem.h"
 #include "core/os_net.h"
 
+/* ip forwarding */
+#define PROC_IPFORWARD_V4 "/proc/sys/net/ipv4/ip_forward"
+#define PROC_IPFORWARD_V6 "/proc/sys/net/ipv6/conf/all/forwarding"
+
+/* Redirect proc entry */
+#define PROC_IF_REDIRECT "/proc/sys/net/ipv4/conf/%s/send_redirects"
+#define PROC_ALL_REDIRECT "/proc/sys/net/ipv4/conf/all/send_redirects"
+
+/* IP spoof proc entry */
+#define PROC_IF_SPOOF "/proc/sys/net/ipv4/conf/%s/rp_filter"
+#define PROC_ALL_SPOOF "/proc/sys/net/ipv4/conf/all/rp_filter"
+
 /* prototypes */
 static int _init(void);
 static void _cleanup(void);
+static void _activate_if_routing(void);
+static void _deactivate_if_routing(void);
+static bool _is_at_least_linuxkernel_2_6_31(void);
+static int _os_linux_writeToProc(const char *file, char *old, char value);
 
 /* global ioctl sockets for ipv4 and ipv6 */
 static int _ioctl_v4, _ioctl_v6;
@@ -64,6 +82,15 @@ struct oonf_subsystem oonf_os_net_subsystem = {
   .cleanup = _cleanup,
 };
 
+/* global procfile state before initialization */
+static char _original_rp_filter;
+static char _original_icmp_redirect;
+static char _original_ipv4_forward;
+static char _original_ipv6_forward;
+
+/* counter of mesh interfaces for ip_forward configuration */
+static int _mesh_count = 0;
+
 /**
  * Initialize os_net subsystem
  * @return -1 if an error happened, 0 otherwise
@@ -233,3 +260,225 @@ os_net_update_interface(struct olsr_interface_data *ifdata,
   freeifaddrs(ifaddrs);
   return 0;
 }
+
+/**
+ * Initialize interface for mesh usage
+ * @param interf pointer to interface object
+ * @return -1 if an error happened, 0 otherwise
+ */
+int
+os_net_init_mesh_if(struct olsr_interface *interf) {
+  char procfile[FILENAME_MAX];
+  char old_redirect = 0, old_spoof = 0;
+
+  /* handle global ip_forward setting */
+  _mesh_count++;
+  if (_mesh_count == 1) {
+    _activate_if_routing();
+  }
+
+  /* Generate the procfile name */
+  snprintf(procfile, sizeof(procfile), PROC_IF_REDIRECT, interf->data.name);
+
+  if (_os_linux_writeToProc(procfile, &old_redirect, '0')) {
+    OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not disable ICMP redirects! "
+        "You should manually ensure that ICMP redirects are disabled!");
+  }
+
+  /* Generate the procfile name */
+  snprintf(procfile, sizeof(procfile), PROC_IF_SPOOF, interf->data.name);
+
+  if (_os_linux_writeToProc(procfile, &old_spoof, '0')) {
+    OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not disable the IP spoof filter! "
+        "You should mannually ensure that IP spoof filtering is disabled!");
+  }
+
+  interf->_original_state = (old_redirect << 8) | (old_spoof);
+  return 0;
+}
+
+/**
+ * Cleanup interface after mesh usage
+ * @param interf pointer to interface object
+ */
+void
+os_net_cleanup_mesh_if(struct olsr_interface *interf) {
+  char restore_redirect, restore_spoof;
+  char procfile[FILENAME_MAX];
+
+  restore_redirect = (interf->_original_state >> 8) & 255;
+  restore_spoof = (interf->_original_state & 255);
+
+  /* Generate the procfile name */
+  snprintf(procfile, sizeof(procfile), PROC_IF_REDIRECT, interf->data.name);
+
+  if (restore_redirect != 0
+      && _os_linux_writeToProc(procfile, NULL, restore_redirect) != 0) {
+    OLSR_WARN(LOG_OS_SYSTEM, "Could not restore ICMP redirect flag %s to %c",
+        procfile, restore_redirect);
+  }
+
+  /* Generate the procfile name */
+  snprintf(procfile, sizeof(procfile), PROC_IF_SPOOF, interf->data.name);
+
+  if (restore_spoof != 0
+      && _os_linux_writeToProc(procfile, NULL, restore_spoof) != 0) {
+    OLSR_WARN(LOG_OS_SYSTEM, "Could not restore IP spoof flag %s to %c",
+        procfile, restore_spoof);
+  }
+
+  /* handle global ip_forward setting */
+  _mesh_count--;
+  if (_mesh_count == 0) {
+    _deactivate_if_routing();
+  }
+
+  interf->_original_state = 0;
+  return;
+}
+
+static void
+_activate_if_routing(void) {
+  if (_os_linux_writeToProc(PROC_IPFORWARD_V4, &_original_ipv4_forward, '1')) {
+    OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not activate ip_forward for ipv4! "
+        "You should manually ensure that ip_forward for ipv4 is activated!");
+  }
+  if (_os_linux_writeToProc(PROC_IPFORWARD_V6, &_original_ipv6_forward, '1')) {
+    OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not activate ip_forward for ipv6! "
+        "You should manually ensure that ip_forward for ipv6 is activated!");
+  }
+
+  if (_os_linux_writeToProc(PROC_ALL_REDIRECT, &_original_icmp_redirect, '0')) {
+    OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not disable ICMP redirects! "
+        "You should manually ensure that ICMP redirects are disabled!");
+  }
+
+  /* check kernel version and disable global rp_filter */
+  if (_is_at_least_linuxkernel_2_6_31()) {
+    if (_os_linux_writeToProc(PROC_ALL_SPOOF, &_original_rp_filter, '0')) {
+      OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not disable global rp_filter "
+          "(necessary for kernel 2.6.31 and newer)! You should manually "
+          "ensure that rp_filter is disabled!");
+    }
+  }
+}
+
+static void
+_deactivate_if_routing(void) {
+  if (_original_icmp_redirect != 0
+      && _os_linux_writeToProc(PROC_ALL_REDIRECT, &_original_icmp_redirect, '0') != 0) {
+    OLSR_WARN(LOG_OS_SYSTEM,
+        "WARNING! Could not restore ICMP redirect flag %s to %c!",
+        PROC_ALL_REDIRECT, _original_icmp_redirect);
+  }
+
+  /* check kernel version and disable global rp_filter */
+  if (_os_linux_writeToProc(PROC_ALL_SPOOF, &_original_rp_filter, '0')) {
+    OLSR_WARN(LOG_OS_SYSTEM,
+        "WARNING! Could not restore global rp_filter flag %s to %c!",
+        PROC_ALL_SPOOF, _original_rp_filter);
+  }
+
+  if (_os_linux_writeToProc(PROC_IPFORWARD_V4, NULL, _original_ipv4_forward)) {
+    OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not restore %s to %c!",
+        PROC_IPFORWARD_V4, _original_ipv4_forward);
+  }
+  if (_os_linux_writeToProc(PROC_IPFORWARD_V6, NULL, _original_ipv6_forward)) {
+    OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not restore flag %s to %c",
+        PROC_IPFORWARD_V6, _original_ipv6_forward);
+  }
+}
+
+
+/**
+ * Overwrite a numeric entry in the procfile system and keep the old
+ * value.
+ * @param file pointer to filename (including full path)
+ * @param old pointer to memory to store old value
+ * @param value new value
+ * @return -1 if an error happened, 0 otherwise
+ */
+static int
+_os_linux_writeToProc(const char *file, char *old, char value) {
+  int fd;
+  char rv;
+
+  if ((fd = open(file, O_RDWR)) < 0) {
+    goto writetoproc_error;
+  }
+
+  if (read(fd, &rv, 1) != 1) {
+    goto writetoproc_error;
+  }
+
+  if (rv != value) {
+    if (lseek(fd, SEEK_SET, 0) == -1) {
+      goto writetoproc_error;
+    }
+
+    if (write(fd, &value, 1) != 1) {
+      goto writetoproc_error;
+    }
+
+    OLSR_DEBUG(LOG_OS_SYSTEM, "Writing '%c' (was %c) to %s", value, rv, file);
+  }
+
+  if (close(fd) != 0) {
+    goto writetoproc_error;
+  }
+
+  if (old && rv != value) {
+    *old = rv;
+  }
+
+  return 0;
+
+writetoproc_error:
+  OLSR_WARN(LOG_OS_SYSTEM,
+    "Error, cannot read proc entry %s: %s (%d)\n",
+    file, strerror(errno), errno);
+  return -1;
+}
+
+/**
+ * @return true if linux kernel is at least 2.6.31
+ */
+static bool
+_is_at_least_linuxkernel_2_6_31(void) {
+  struct utsname uts;
+  char *next;
+  int first = 0, second = 0, third = 0;
+
+  memset(&uts, 0, sizeof(uts));
+  if (uname(&uts)) {
+    OLSR_WARN(LOG_OS_SYSTEM,
+        "Error, could not read kernel version: %s (%d)\n",
+        strerror(errno), errno);
+    return false;
+  }
+
+  first = strtol(uts.release, &next, 10);
+  /* check for linux 3.x */
+  if (first >= 3) {
+    return true;
+  }
+
+  if (*next != '.') {
+    goto kernel_parse_error;
+  }
+
+  second = strtol(next+1, &next, 10);
+  if (*next != '.') {
+    goto kernel_parse_error;
+  }
+
+  third = strtol(next+1, NULL, 10);
+
+  /* better or equal than linux 2.6.31 ? */
+  return first == 2 && second == 6 && third >= 31;
+
+kernel_parse_error:
+  OLSR_WARN(LOG_OS_SYSTEM,
+      "Error, cannot parse kernel version: %s\n", uts.release);
+  return false;
+}
index d89e40c..0fc01e1 100644 (file)
 /* and now the rest of the includes */
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
-#include <sys/utsname.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
 
 #include "common/common_types.h"
-#include "core/olsr_timer.h"
 #include "core/olsr_subsystem.h"
 #include "core/os_routing.h"
 #include "core/os_system.h"
 
-/* ip forwarding */
-#define PROC_IPFORWARD_V4 "/proc/sys/net/ipv4/ip_forward"
-#define PROC_IPFORWARD_V6 "/proc/sys/net/ipv6/conf/all/forwarding"
-
-/* Redirect proc entry */
-#define PROC_IF_REDIRECT "/proc/sys/net/ipv4/conf/%s/send_redirects"
-#define PROC_ALL_REDIRECT "/proc/sys/net/ipv4/conf/all/send_redirects"
-
-/* IP spoof proc entry */
-#define PROC_IF_SPOOF "/proc/sys/net/ipv4/conf/%s/rp_filter"
-#define PROC_ALL_SPOOF "/proc/sys/net/ipv4/conf/all/rp_filter"
-
 /* prototypes */
 static int _init(void);
 static void _cleanup(void);
@@ -75,24 +58,12 @@ static void _cleanup(void);
 static int _routing_set(struct nlmsghdr *msg, struct os_route *route,
     unsigned char rt_type, unsigned char rt_scope);
 
-static bool _is_at_least_linuxkernel_2_6_31(void);
-static int _os_linux_writeToProc(const char *file, char *old, char value);
-
 static void _routing_finished(struct os_route *route, int error);
 static void _cb_rtnetlink_message(struct nlmsghdr *);
 static void _cb_rtnetlink_error(uint32_t seq, int error);
 static void _cb_rtnetlink_done(uint32_t seq);
 static void _cb_rtnetlink_timeout(void);
 
-/* global procfile state before initialization */
-static char _original_rp_filter;
-static char _original_icmp_redirect;
-static char _original_ipv4_forward;
-static char _original_ipv6_forward;
-
-/* counter of mesh interfaces for ip_forward configuration */
-static int _mesh_count = 0;
-
 /* netlink socket for route set/get commands */
 struct os_system_netlink _rtnetlink_socket = {
   .cb_message = _cb_rtnetlink_message,
@@ -129,21 +100,6 @@ _init(void) {
   if (os_system_netlink_add(&_rtnetlink_socket, NETLINK_ROUTE)) {
     return -1;
   }
-
-  if (_os_linux_writeToProc(PROC_ALL_REDIRECT, &_original_icmp_redirect, '0')) {
-    OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not disable ICMP redirects! "
-        "You should manually ensure that ICMP redirects are disabled!");
-  }
-
-  /* check kernel version and disable global rp_filter */
-  if (_is_at_least_linuxkernel_2_6_31()) {
-    if (_os_linux_writeToProc(PROC_ALL_SPOOF, &_original_rp_filter, '0')) {
-      OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not disable global rp_filter "
-          "(necessary for kernel 2.6.31 and newer)! You should manually "
-          "ensure that rp_filter is disabled!");
-    }
-  }
-
   list_init_head(&_rtnetlink_feedback);
   return 0;
 }
@@ -159,134 +115,9 @@ _cleanup(void) {
     _routing_finished(rt, 1);
   }
 
-  if (_original_icmp_redirect != 0
-      && _os_linux_writeToProc(PROC_ALL_REDIRECT, &_original_icmp_redirect, '0') != 0) {
-    OLSR_WARN(LOG_OS_SYSTEM,
-        "WARNING! Could not restore ICMP redirect flag %s to %c!",
-        PROC_ALL_REDIRECT, _original_icmp_redirect);
-  }
-
-  /* check kernel version and disable global rp_filter */
-  if (_os_linux_writeToProc(PROC_ALL_SPOOF, &_original_rp_filter, '0')) {
-    OLSR_WARN(LOG_OS_SYSTEM,
-        "WARNING! Could not restore global rp_filter flag %s to %c!",
-        PROC_ALL_SPOOF, _original_rp_filter);
-  }
-
-  if (_mesh_count > 0) {
-    if (_os_linux_writeToProc(PROC_IPFORWARD_V4, NULL, _original_ipv4_forward)) {
-      OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not restore %s to %c!",
-          PROC_IPFORWARD_V4, _original_ipv4_forward);
-    }
-    if (_os_linux_writeToProc(PROC_IPFORWARD_V6, NULL, _original_ipv6_forward)) {
-      OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not restore flag %s to %c",
-          PROC_IPFORWARD_V6, _original_ipv6_forward);
-    }
-  }
-
   os_system_netlink_remove(&_rtnetlink_socket);
 }
 
-/**
- * Initialize interface for mesh usage
- * @param interf pointer to interface object
- * @return -1 if an error happened, 0 otherwise
- */
-int
-os_routing_init_mesh_if(struct olsr_interface *interf) {
-  char procfile[FILENAME_MAX];
-  char old_redirect = 0, old_spoof = 0;
-
-  if (!oonf_subsystem_is_initialized(&oonf_os_routing_subsystem)) {
-    /* make interface listener work without routing core */
-    return 0;
-  }
-
-  /* handle global ip_forward setting */
-  _mesh_count++;
-  if (_mesh_count == 1) {
-    if (_os_linux_writeToProc(PROC_IPFORWARD_V4, &_original_ipv4_forward, '1')) {
-      OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not activate ip_forward for ipv4! "
-          "You should manually ensure that ip_forward for ipv4 is activated!");
-    }
-    if (_os_linux_writeToProc(PROC_IPFORWARD_V6, &_original_ipv6_forward, '1')) {
-      OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not activate ip_forward for ipv6! "
-          "You should manually ensure that ip_forward for ipv6 is activated!");
-    }
-  }
-
-  /* Generate the procfile name */
-  snprintf(procfile, sizeof(procfile), PROC_IF_REDIRECT, interf->data.name);
-
-  if (_os_linux_writeToProc(procfile, &old_redirect, '0')) {
-    OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not disable ICMP redirects! "
-        "You should manually ensure that ICMP redirects are disabled!");
-  }
-
-  /* Generate the procfile name */
-  snprintf(procfile, sizeof(procfile), PROC_IF_SPOOF, interf->data.name);
-
-  if (_os_linux_writeToProc(procfile, &old_spoof, '0')) {
-    OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not disable the IP spoof filter! "
-        "You should mannually ensure that IP spoof filtering is disabled!");
-  }
-
-  interf->_original_state = (old_redirect << 8) | (old_spoof);
-  return 0;
-}
-
-/**
- * Cleanup interface after mesh usage
- * @param interf pointer to interface object
- */
-void
-os_routing_cleanup_mesh_if(struct olsr_interface *interf) {
-  char restore_redirect, restore_spoof;
-  char procfile[FILENAME_MAX];
-
-  if (!oonf_subsystem_is_initialized(&oonf_os_routing_subsystem)) {
-    /* make interface listener work without routing core */
-    return;
-  }
-
-  restore_redirect = (interf->_original_state >> 8) & 255;
-  restore_spoof = (interf->_original_state & 255);
-
-  /* Generate the procfile name */
-  snprintf(procfile, sizeof(procfile), PROC_IF_REDIRECT, interf->data.name);
-
-  if (restore_redirect != 0
-      && _os_linux_writeToProc(procfile, NULL, restore_redirect) != 0) {
-    OLSR_WARN(LOG_OS_SYSTEM, "Could not restore ICMP redirect flag %s to %c",
-        procfile, restore_redirect);
-  }
-
-  /* Generate the procfile name */
-  snprintf(procfile, sizeof(procfile), PROC_IF_SPOOF, interf->data.name);
-
-  if (restore_spoof != 0
-      && _os_linux_writeToProc(procfile, NULL, restore_spoof) != 0) {
-    OLSR_WARN(LOG_OS_SYSTEM, "Could not restore IP spoof flag %s to %c",
-        procfile, restore_spoof);
-  }
-
-  /* handle global ip_forward setting */
-  _mesh_count--;
-  if (_mesh_count == 0) {
-    if (_os_linux_writeToProc(PROC_IPFORWARD_V4, NULL, _original_ipv4_forward)) {
-      OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not restore %s to %c!",
-          PROC_IPFORWARD_V4, _original_ipv4_forward);
-    }
-    if (_os_linux_writeToProc(PROC_IPFORWARD_V6, NULL, _original_ipv6_forward)) {
-      OLSR_WARN(LOG_OS_SYSTEM, "WARNING! Could not restore flag %s to %c",
-          PROC_IPFORWARD_V6, _original_ipv6_forward);
-    }
-  }
-
-  interf->_original_state = 0;
-  return;
-}
-
 /**
  * Update an entry of the kernel routing table. This call will only trigger
  * the change, the real change will be done as soon as the netlink socket is
@@ -688,96 +519,3 @@ _cb_rtnetlink_done(uint32_t seq) {
     }
   }
 }
-
-/**
- * Overwrite a numeric entry in the procfile system and keep the old
- * value.
- * @param file pointer to filename (including full path)
- * @param old pointer to memory to store old value
- * @param value new value
- * @return -1 if an error happened, 0 otherwise
- */
-static int
-_os_linux_writeToProc(const char *file, char *old, char value) {
-  int fd;
-  char rv;
-
-  if ((fd = open(file, O_RDWR)) < 0) {
-    goto writetoproc_error;
-  }
-
-  if (read(fd, &rv, 1) != 1) {
-    goto writetoproc_error;
-  }
-
-  if (rv != value) {
-    if (lseek(fd, SEEK_SET, 0) == -1) {
-      goto writetoproc_error;
-    }
-
-    if (write(fd, &value, 1) != 1) {
-      goto writetoproc_error;
-    }
-
-    OLSR_DEBUG(LOG_OS_SYSTEM, "Writing '%c' (was %c) to %s", value, rv, file);
-  }
-
-  if (close(fd) != 0) {
-    goto writetoproc_error;
-  }
-
-  if (old && rv != value) {
-    *old = rv;
-  }
-
-  return 0;
-
-writetoproc_error:
-  OLSR_WARN(LOG_OS_SYSTEM,
-    "Error, cannot read proc entry %s: %s (%d)\n",
-    file, strerror(errno), errno);
-  return -1;
-}
-
-/**
- * @return true if linux kernel is at least 2.6.31
- */
-static bool
-_is_at_least_linuxkernel_2_6_31(void) {
-  struct utsname uts;
-  char *next;
-  int first = 0, second = 0, third = 0;
-
-  memset(&uts, 0, sizeof(uts));
-  if (uname(&uts)) {
-    OLSR_WARN(LOG_OS_SYSTEM,
-        "Error, could not read kernel version: %s (%d)\n",
-        strerror(errno), errno);
-    return false;
-  }
-
-  first = strtol(uts.release, &next, 10);
-  /* check for linux 3.x */
-  if (first >= 3) {
-    return true;
-  }
-
-  if (*next != '.') {
-    goto kernel_parse_error;
-  }
-
-  second = strtol(next+1, &next, 10);
-  if (*next != '.') {
-    goto kernel_parse_error;
-  }
-
-  third = strtol(next+1, NULL, 10);
-
-  /* better or equal than linux 2.6.31 ? */
-  return first == 2 && second == 6 && third >= 31;
-
-kernel_parse_error:
-  OLSR_WARN(LOG_OS_SYSTEM,
-      "Error, cannot parse kernel version: %s\n", uts.release);
-  return false;
-}
index 57b466a..2005811 100644 (file)
 #include <unistd.h>
 #include <sys/select.h>
 
+#include "common/avl.h"
 #include "common/common_types.h"
+#include "common/list.h"
 #include "common/netaddr.h"
 #include "core/olsr_logging.h"
+#include "core/olsr_timer.h"
 
 struct olsr_interface_data {
   /* Interface addresses with mesh-wide scope (at least) */
@@ -73,6 +76,36 @@ struct olsr_interface_data {
   bool up;
 };
 
+struct olsr_interface {
+  /* data of interface */
+  struct olsr_interface_data data;
+
+  /*
+   * usage counter to allow multiple instances to add the same
+   * interface
+   */
+  int usage_counter;
+
+  /*
+   * usage counter to keep track of the number of users on
+   * this interface who want to send mesh traffic
+   */
+  int mesh_counter;
+
+  /*
+   * used to store internal state of interfaces before
+   * configuring them for manet data forwarding.
+   * Only used by os_specific code.
+   */
+  uint32_t _original_state;
+
+  /* hook interfaces into tree */
+  struct avl_node _node;
+
+  /* timer for lazy interface change handling */
+  struct olsr_timer_entry _change_timer;
+};
+
 /* pre-declare inlines */
 static INLINE int os_net_bindto_interface(int, struct olsr_interface_data *data);
 static INLINE int os_close(int fd);
@@ -108,4 +141,7 @@ EXPORT int os_recvfrom(int fd, void *buf, size_t length,
 EXPORT int os_sendto(
     int fd, const void *buf, size_t length, union netaddr_socket *dst);
 
+EXPORT int os_net_init_mesh_if(struct olsr_interface *);
+EXPORT void os_net_cleanup_mesh_if(struct olsr_interface *);
+
 #endif /* OS_NET_H_ */
index f853ac2..8102084 100644 (file)
@@ -121,9 +121,6 @@ EXPORT extern struct oonf_subsystem oonf_os_routing_subsystem;
 EXPORT extern const struct os_route OS_ROUTE_WILDCARD;
 
 /* prototypes for all os_routing functions */
-EXPORT int os_routing_init_mesh_if(struct olsr_interface *);
-EXPORT void os_routing_cleanup_mesh_if(struct olsr_interface *);
-
 EXPORT int os_routing_set(struct os_route *, bool set, bool del_similar);
 EXPORT int os_routing_query(struct os_route *);
 EXPORT void os_routing_interrupt(struct os_route *);