set Motorola-Canopy-Gateway, RT#41261
[freeside.git] / FS / FS / svc_IP_Mixin.pm
index 5b06082..abafe86 100644 (file)
@@ -1,9 +1,12 @@
 package FS::svc_IP_Mixin;
+use base 'FS::IP_Mixin';
 
 use strict;
-use base 'FS::IP_Mixin';
-use FS::Record qw(qsearchs qsearch);
 use NEXT;
+use FS::Record qw(qsearchs qsearch);
+use FS::Conf;
+use FS::router;
+use FS::part_svc_router;
 
 =item addr_block
 
@@ -183,16 +186,30 @@ means "Framed-Route" if there's an attached router.
 
 sub radius_reply {
   my $self = shift;
-  my %reply;
-  my ($block) = $self->attached_block;
-  if ( $block ) {
+  my %reply = ();
+  if ( my $block = $self->attached_block ) {
     # block routed over dynamic IP: "192.168.100.0/29 0.0.0.0 1"
     # or
     # block routed over fixed IP: "192.168.100.0/29 192.168.100.1 1"
     # (the "1" at the end is the route metric)
-    $reply{'Framed-Route'} =
-    $block->cidr . ' ' .
-    ($self->ip_addr || '0.0.0.0') . ' 1';
+    $reply{'Framed-Route'} = $block->cidr . ' ' .
+                             ($self->ip_addr || '0.0.0.0') . ' 1';
+  }
+
+  if ( $self->router_routernum && FS::Conf->new->exists('radius-canopy') ) {
+    my @addr_block =
+      qsearch('addr_block', { routernum => $self->router_routernum } );
+    if ( @addr_block ) {
+
+      #?
+      warn "Multiple address blocks attached to this service's router; using first"
+        if scalar(@addr_block) > 1;
+
+      $reply{'Motorola-Canopy-Gateway'} = $addr_block[0]->ip_gateway
+
+    }
+    
   }
   %reply;
 }