Add insert_filter() function
[people/xl0/gpxe.git] / src / net / filter.c
index 7d93c61..c4542fc 100644 (file)
@@ -23,6 +23,7 @@
  */
 
 #include <stddef.h>
+#include <errno.h>
 #include <gpxe/stream.h>
 #include <gpxe/filter.h>
 
@@ -161,3 +162,26 @@ int filter_kick ( struct stream_connection *conn ) {
 
        return stream_kick ( &filter->downstream );
 }
+
+/**
+ * Insert filter into stream
+ *
+ * @v app              Stream application
+ * @v filter           Filter stream
+ * @ret rc             Return status code
+ */
+int insert_filter ( struct stream_application *app,
+                   struct filter_stream *filter ) {
+       struct stream_connection *conn = app->conn;
+
+       if ( ! app->conn ) {
+               DBGC ( filter, "Filter %p cannot insert onto closed stream\n",
+                      filter );
+               return -ENOTCONN;
+       }
+
+       app->conn = &filter->upstream;
+       conn->app = &filter->downstream;
+
+       return 0;
+}