Date: 202001
Location: OEJD.ARTCC, FO
Aircraft: Commercial Fixed Wing
Operator: Air Carrier
Operating under: Part 121
Flight plan: IFR
Flight phase: Parked; Climb
ATC / advisory: Center OEJD
Reporter organization: Air Carrier
Reporter function: Captain
Reporter qualification: Flight Crew Air Transport Pilot (ATP); Flight Crew Instrument; Flight Crew Multiengine
Human factors: Time Pressure; Communication Breakdown
Second reporter function: First Officer
Anomaly: ATC Issue All Types; Deviation - Track / Heading All Types; Deviation / Discrepancy - Procedural Published Material / Policy; Deviation / Discrepancy - Procedural Clearance
Detector: Person Flight Crew
When detected: In-flight
Result: Air Traffic Control Issued New Clearance; Flight Crew Took Evasive Action; Flight Crew Requested ATC Assistance / Clarification
Contributing factors: Airspace Structure; Procedure
Primary problem: Airspace Structure

Narrative: Unable to obtain clearance from departure airport in Doha; Qatar as flight planned for ZZZZ1 due to Saudi refusing our filed route. Doha relays the 'preferred' routing over the restricted gulf region. Dispatch unable to produce a [flight plan] with the preferred routing due to the NOTAM and performance engineering having more or less blacked out those specific routes in the software. Dispatch escalated and involves some of the duty pilots and managers while also speaking directly with Saudi; Bahrain; and Doha. Dispatch is able to refile us only by free text for the preferred route and ATC accepts the refiling. We obtain clearance and launch to ZZZZ1 without a valid signed [flight plan] in hand because there is no other possible way to do it. Dispatch can't even generate a new top sheet to send via ACARS for fuel planning purposes because of the block in the software. Thinking outside the box is the order of the day.  After departure; Doha vectors us off route straight toward Iran due to traffic congestion and says to expect to remain on that heading for 4 minutes. That time frame will put us well into Tehran. I inform Doha my intentions if that is what they expect to be their plan while also trying to mitigate that threat with Tehran ADIZ of which Tehran will not answer any radio calls. We initiate min clean speed at FL230 and prepare to declare MayDay if necessary at a specific point to justify a turn away from Iran. Min clean is approved and we are issued small step climbs higher. We are shortly turned back onto our route ultimately placing us within 10 nm of Tehran. Transferred to next sector and scolded for still being filed on the wrong route even though it was the preferred route relayed to us on the ground by Doha. Rerouted differently again. Finally made it to FL360; normal speed; over the gulf for the entire flight; at least we are going away from Tehran. Given the latest in the gulf region; the guideline NOTAMs; the FAA clarifications issued; and exceptions granted; you all need to be aware that ultimately Saudi is going to be in control of their airspace regardless of what the USA FAA says; that while showing the FAA we at [Company] are mitigating the threat by restricting the software from planning anything over the gulf; that alone presents a caveat of having to decide whether or not to launch without a valid [flight plan] in hand by the PIC and the Dispatcher when Saudi refuses to approve a clearance as filed.


Second narrative: [Report narrative contained no additional information.]


Synopsis: Air carrier flight crew reported being vectored off route toward Tehran ADIZ; placing the flight at risk for penetrating the restricted airspace.